第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C# Soap XML SerializationException 解析到對象時

C# Soap XML SerializationException 解析到對象時

C#
胡子哥哥 2022-06-19 16:41:53
當我嘗試將soap xml解析為對象時,我遇到了異常,不確定我做錯了什么。例外:System.Runtime.Serialization.dll 中出現(xiàn)“System.Runtime.Serialization.SerializationException”類型的未處理異常附加信息:第 1 行位置 687 中的錯誤。元素“ http://soap.sforce.com/2005/09/outbound:sObject ”包含映射到名稱“urn:sobject.enterprise.soap.sforce”的類型的數(shù)據(jù).com:聯(lián)系方式”。反序列化器不知道映射到此名稱的任何類型。如果您正在使用 DataContractSerializer,請考慮使用 DataContractResolver,或者將與“Contact”對應的類型添加到已知類型列表中 - 例如,通過使用 KnownTypeAttribute 屬性或?qū)⑵涮砑拥絺鬟f給序列化程序的已知類型列表中。 static void Main(string[] args)    {        string inputString = "<?xml version=\"1.0\" encoding=\"UTF - 8\"?> <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"> <soapenv:Body> <notifications xmlns=\"http://soap.sforce.com/2005/09/outbound\"> <SessionId xsi:nil=\"true\"/> <EnterpriseUrl>https://hultibs--FullDev.cs10.my.salesforce.com/services/Soap/c/44.0/00DJ0000003QX7f</EnterpriseUrl> <PartnerUrl>https://hultibs--FullDev.cs10.my.salesforce.com/services/Soap/u/44.0/00DJ0000003QX7f</PartnerUrl> <Notification> <Id>04lJ000000PoRS2IAN</Id> <sObject xsi:type=\"sf:Contact\" xmlns:sf=\"urn:sobject.enterprise.soap.sforce.com\"> <sf:Id>0033600001koT9qAAE</sf:Id> <sf:Email>tcampbell2018@maili.com</sf:Email> <sf:Student_ID__c>5192435</sf:Student_ID__c> </sObject> </Notification> </notifications> </soapenv:Body> </soapenv:Envelope>";        FromXml(inputString);        Console.ReadLine();    } public static void FromXml(string Xml)    {        using (var reader = XmlReader.Create(new StringReader(Xml)))        {            Message m = Message.CreateMessage(reader, int.MaxValue, MessageVersion.Soap11);            var body = m.GetBody<Notifications>();            Console.WriteLine(body);        }    }
查看完整描述

2 回答

?
MMMHUHU

TA貢獻1834條經(jīng)驗 獲得超8個贊

異常中描述的問題在于soap消息中sObject的以下類型和命名空間聲明


<sObject xsi:type=\"sf:Contact\" xmlns:sf=\"urn:sobject.enterprise.soap.sforce.com\">

因為在該命名空間(或任何其他)中沒有定義類 Contact。


如果您從肥皂消息中的 sObject 中刪除類型和命名空間聲明(并從其成員中刪除 sf: 前綴),它應該可以正常工作。


或刪除xsi:type=\"sf:Contact\并將 DataContract 更改為


[DataContract(Name = "sObject", Namespace = "urn:sobject.enterprise.soap.sforce.com")]

或者留下肥皂信息,然后改變


    [DataContract(Name = "sObject", Namespace = "http://soap.sforce.com/2005/09/outbound")]

    public class SObject


    [DataContract(Name = "Contact", Namespace = "urn:sobject.enterprise.soap.sforce.com")]

    public class Contact

也在變化(在通知中)


        [DataMember(Name = "sObject", Order = 2)]

        public SObject SObject { get; set; }


        [DataMember(Name = "sObject", Order = 2)]

        public Contact SObject { get; set; }


查看完整回答
反對 回復 2022-06-19
?
蝴蝶不菲

TA貢獻1810條經(jīng)驗 獲得超4個贊

您只需在 DataContract 中聲明一個命名空間“ http://soap.sforce.com/2005/09/outbound ”,您可以使用 Message.CreateMessage 序列化您的通知并將您的 xml 與序列化消息進行比較。


下面是代碼。


static void Main(string[] args)

    {

        Notifications notifications = new Notifications()

        {

            ActionId = "actionId",

            EnterpriseUrl = "enterpriceUri",

            PartnerUrl = "parentUri",

            Notification = new Notification

            {

                Id = "abc",

                SObject = new SObject

                {

                    Email = "email",

                    Id = "id",

                    Sf = "sf",

                    Student_ID__c = "a",

                    Type = "type"

                }

            }

        };

        Message me = Message.CreateMessage(MessageVersion.Soap11, "www.abc.com", notifications);  // create a message and serialize the notifications into the message

        WriteMessage(me, @"d:\message.xml");



    }

    static void WriteMessage(Message message, string fileName)

    {


        using (XmlWriter writer = new XmlTextWriter(fileName, Encoding.UTF8))

        {

            message.WriteMessage(writer);// write the message into a file

        }

        Process.Start(fileName);// show the file

    }

和序列化的消息。


<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">www.abc.com</Action></s:Header><s:Body><notifications xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://soap.sforce.com/2005/09/outbound"><ActionId>actionId</ActionId><EnterpriseUrl>enterpriceUri</EnterpriseUrl><PartnerUrl>parentUri</PartnerUrl><Notification><Id>abc</Id><sObject><Id>id</Id><Email>email</Email><Student_ID__c>a</Student_ID__c><type>type</type><sf>sf</sf></sObject></Notification></notifications></s:Body></s:Envelope>



查看完整回答
反對 回復 2022-06-19
  • 2 回答
  • 0 關注
  • 261 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號