c# - XElement not declared when using Service Reference Proxy with XmlAnyElementAttribute -
i working on windows phone 7 app talks 3rd party soap service. used add service reference
wsdl generate proxy class. calls work, outbound calls make use of 'sobject
' class result in error "the type system.xml.linq.xelement not expected. use xmlinclude or soapinclude attribute specify types not known statically"
the relevant part of sobject class defined (as autogenerated)
[system.codedom.compiler.generatedcodeattribute("system.xml", "4.0.30319.1")] [system.diagnostics.debuggerstepthroughattribute()] [system.xml.serialization.xmltypeattribute(namespace="urn:sobject.partner.soap.sforce.com")] public partial class sobject : object, system.componentmodel.inotifypropertychanged { <snipped ....> [system.xml.serialization.xmlanyelementattribute(namespace="urn:sobject.partner.soap.sforce.com", order=3)] public system.xml.linq.xelement[] { { return this.anyfield; } set { this.anyfield = value; this.raisepropertychanged("any"); } }
the code use create sobject:
sobject post = new sobject(); xelement postels = new xelement("sobject", new xelement("type", "textpost"), new xelement("parentid", userinfo.userid), new xelement("body", postbody) ); post.any = postels.elements().toarray();
steps have tried:
adding [system.xml.serialization.xmlinclude(typeof(system.xml.linq.xelement))]
sobject class. same error, seems should have worked.
adding [system.xml.serialization.xmlelement()]
property. when did message serialized, -as expected- incorrect (the elements should not there, goal xelements[] output)
<sobject> <type xmlns="urn:sobject.partner.soap.sforce.com">feedpost</type> <id xsi:nil="true" xmlns="urn:sobject.partner.soap.sforce.com" /> <any xmlns="urn:sobject.partner.soap.sforce.com"> <type xmlns="">textpost</type> </any> <any xmlns="urn:sobject.partner.soap.sforce.com"> <parentid xmlns="">xxxxxx</parentid> </any> <any xmlns="urn:sobject.partner.soap.sforce.com"> <body xmlns="">test post wp7!</body> </any> </sobject>
as aside, suspect related, calls return sobjects inbound 3rd party service have property null, despite data being there in rpc response.
it turns out exception due serialization of xelement[], issue in windows phone 7.
as noted vijay verma here, linked msdn article on xmlserializer.serialize states under platform notes:
silverlight windows phone: xmlserializer.serialize method throws invalidoperationexception if xmlserializer object initialized type parameter contains array of objects of type xelement.
vijay listed workaround of using single xelement , parsing field separately. work if control both sides of soap message. unfortunately not request invalid on 3rd party's side.
this explains invalidoperationexception xelement not expected, although not answer hoping for. helps else may have control on both sides of service.
Comments
Post a Comment