Wednesday 15 June 2011

xml - .Net (C#) cannot deserialize Java web service response -



xml - .Net (C#) cannot deserialize Java web service response -

i consuming java based web service .net application. problem arise, when got deserialized response web service, of fields in response comes null values, if @ xml response, response has proper values. guess main problem .net cannot deserialize response properly. here wsdl, method using "getforeignenterpriselist".

xml response is

<s:envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" /> <s:body> <ns6:getforeignenterpriselistresponse xmlns="http://api.vetrf.ru/schema/base" xmlns:ns2="http://api.vetrf.ru/schema/argus" xmlns:ns3="http://api.vetrf.ru/schema/institutions" xmlns:ns4="http://api.vetrf.ru/schema/ikar" xmlns:ns5="http://api.vetrf.ru/schema/base/register" xmlns:ns6="http://api.vetrf.ru/schema/argus/enterprise/ws-definitions" xmlns:ns7="http://api.vetrf.ru/schema/argus/ws-definitions"> <ns2:enterpriselist offset="0" total="14058" count="1"> <ns2:enterprise> <uuid>06e4a78e-053d-11e1-99b4-d8d385fbc9e8</uuid> <guid>cb1483ab-2c7d-db46-445c-09849ae9b761</guid> <active>true</active> <last>true</last> <status>100</status> <createdate>2009-10-08t12:50:47+04:00</createdate> <updatedate>2009-10-08t12:50:47+04:00</updatedate> <ns2:name>cargill meat solutions corporation</ns2:name> <ns2:englishname> </ns2:englishname> <ns2:activity>Убой КРС, разделка, хранение говядины</ns2:activity> <ns2:englishactivity>cattle slaughter, beef cutting, beef storage</ns2:englishactivity> <ns4:address> <ns4:addressview>friona</ns4:addressview> <ns4:enaddressview> </ns4:enaddressview> </ns4:address> <ns4:country> <uuid>91134526-4373-ec59-4a1e-e0e99bd50b7b</uuid> <guid>cac8a802-3c65-397d-895d-c0495bf6ea61</guid> </ns4:country> <ns4:region> <uuid>c7bad316-6564-787c-c502-6a9e8afdc093</uuid> <guid>bbee471c-0548-7190-cca9-5897eedbeac3</guid> <ns4:hasstreets>false</ns4:hasstreets> </ns4:region> <ns2:numberlist> <ns2:enterprisenumber>86 Е</ns2:enterprisenumber> </ns2:numberlist> </ns2:enterprise> </ns2:enterpriselist> </ns6:getforeignenterpriselistresponse> </s:body> </s:envelope>

this .net generated class enterprise node need get.

class="snippet-code-html lang-html prettyprint-override">[system.codedom.compiler.generatedcodeattribute("system.xml", "4.0.30319.18408")] [system.serializableattribute()] [system.diagnostics.debuggerstepthroughattribute()] [system.componentmodel.designercategoryattribute("code")] [system.xml.serialization.xmltypeattribute(namespace="http://api.vetrf.ru/schema/argus")] public partial class enterprise : genericversioningentity { private string namefield; private string englishnamefield; private string activityfield; private string englishactivityfield; private address addressfield; private country countryfield; private part regionfield; private district districtfield; private string[] numberlistfield; private string typefield; /// <remarks/> [system.xml.serialization.xmlelementattribute(order=0)] public string name { { homecoming this.namefield; } set { this.namefield = value; this.raisepropertychanged("name"); } } /// <remarks/> [system.xml.serialization.xmlelementattribute(order=1)] public string englishname { { homecoming this.englishnamefield; } set { this.englishnamefield = value; this.raisepropertychanged("englishname"); } } /// <remarks/> [system.xml.serialization.xmlelementattribute(order=2)] public string activity { { homecoming this.activityfield; } set { this.activityfield = value; this.raisepropertychanged("activity"); } } /// <remarks/> [system.xml.serialization.xmlelementattribute(order=3)] public string englishactivity { { homecoming this.englishactivityfield; } set { this.englishactivityfield = value; this.raisepropertychanged("englishactivity"); } } /// <remarks/> [system.xml.serialization.xmlelementattribute(order=4)] public address address { { homecoming this.addressfield; } set { this.addressfield = value; this.raisepropertychanged("address"); } } /// <remarks/> [system.xml.serialization.xmlelementattribute(order=5)] public country country { { homecoming this.countryfield; } set { this.countryfield = value; this.raisepropertychanged("country"); } } /// <remarks/> [system.xml.serialization.xmlelementattribute(order=6)] public part region { { homecoming this.regionfield; } set { this.regionfield = value; this.raisepropertychanged("region"); } } /// <remarks/> [system.xml.serialization.xmlelementattribute(order=7)] public district district { { homecoming this.districtfield; } set { this.districtfield = value; this.raisepropertychanged("district"); } } /// <remarks/> [system.xml.serialization.xmlarrayattribute(order=8)] [system.xml.serialization.xmlarrayitemattribute("enterprisenumber", isnullable=false)] public string[] numberlist { { homecoming this.numberlistfield; } set { this.numberlistfield = value; this.raisepropertychanged("numberlist"); } } /// <remarks/> [system.xml.serialization.xmlelementattribute(datatype="integer", order=9)] public string type { { homecoming this.typefield; } set { this.typefield = value; this.raisepropertychanged("type"); } } }

.net cannot deserialize "address", "country", "region", "numberlist" nodes.

and illustration of how .net generated class country node comes null.

class="snippet-code-html lang-html prettyprint-override">[system.codedom.compiler.generatedcodeattribute("system.xml", "4.0.30319.18408")] [system.serializableattribute()] [system.diagnostics.debuggerstepthroughattribute()] [system.componentmodel.designercategoryattribute("code")] [system.xml.serialization.xmltypeattribute(namespace="http://api.vetrf.ru/schema/ikar")] public partial class country : genericversioningentity { private string namefield; private string fullnamefield; private string englishnamefield; private string codefield; private string code3field; private bool isrussiafield; private bool isrussiafieldspecified; private bool iscustomsunionfield; private bool iscustomsunionfieldspecified; /// <remarks/> [system.xml.serialization.xmlelementattribute(order=0)] public string name { { homecoming this.namefield; } set { this.namefield = value; this.raisepropertychanged("name"); } } /// <remarks/> [system.xml.serialization.xmlelementattribute(order=1)] public string fullname { { homecoming this.fullnamefield; } set { this.fullnamefield = value; this.raisepropertychanged("fullname"); } } /// <remarks/> [system.xml.serialization.xmlelementattribute(order=2)] public string englishname { { homecoming this.englishnamefield; } set { this.englishnamefield = value; this.raisepropertychanged("englishname"); } } /// <remarks/> [system.xml.serialization.xmlelementattribute(order=3)] public string code { { homecoming this.codefield; } set { this.codefield = value; this.raisepropertychanged("code"); } } /// <remarks/> [system.xml.serialization.xmlelementattribute(order=4)] public string code3 { { homecoming this.code3field; } set { this.code3field = value; this.raisepropertychanged("code3"); } } /// <remarks/> [system.xml.serialization.xmlelementattribute(order=5)] public bool isrussia { { homecoming this.isrussiafield; } set { this.isrussiafield = value; this.raisepropertychanged("isrussia"); } } /// <remarks/> [system.xml.serialization.xmlignoreattribute()] public bool isrussiaspecified { { homecoming this.isrussiafieldspecified; } set { this.isrussiafieldspecified = value; this.raisepropertychanged("isrussiaspecified"); } } /// <remarks/> [system.xml.serialization.xmlelementattribute(order=6)] public bool iscustomsunion { { homecoming this.iscustomsunionfield; } set { this.iscustomsunionfield = value; this.raisepropertychanged("iscustomsunion"); } } /// <remarks/> [system.xml.serialization.xmlignoreattribute()] public bool iscustomsunionspecified { { homecoming this.iscustomsunionfieldspecified; } set { this.iscustomsunionfieldspecified = value; this.raisepropertychanged("iscustomsunionspecified"); } } }

any ideas?

its because of xml namespaces, of ns2: , ns4: etc.

you strip these out of message text including namespace declarations, hacky quick. or including names spaces in object this

xmlroot(namespace = "http://api.vetrf.ru/schema/")] public class enterprise { [xmlelement(namespace = "http://api.vetrf.ru/schema/ikar")] public address address{ get; set; } [xmlelement(namespace = "http://api.vetrf.ru/schema/ikar")] public country country { get; set; } ... } xmlroot(namespace = "http://api.vetrf.ru/schema/ikar")] public class address { .... }

havent tried guess, luck!

c# xml web-services wsdl

No comments:

Post a Comment