Featured post
c# - Invoke a SOAP method with namespace prefixes -
my c# web service client sends following soap message java-based web service:
<?xml version="1.0" encoding="utf-8"?> <soap:envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <soap:body> <getdata> <request> <requestparameters xmlns="http://b..."> <equals> ... </equals> </requestparameters> </request> </getdata> </soap:body> </soap:envelope>
and java-based web service returns error:
500 internal server error ... cannot find dispatch method {}getdata ...
client written in java, works, sends following message:
<?xml version="1.0" encoding="utf-8"?> <soap:envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <soap:body> <ns2:getdata xmlns:ns2="http://a..."> <ns2:request> <ns3:requestparameters xmlns:ns3="http://b..."> <ns3:equals> ... </ns3:equals> </ns3:requestparameters> </ns2:request> </ns2:getdata> </soap:body> </soap:envelope>
is there easy way in c# send soap messages same way java client sends: namespace prefixes?
following c# code sends message:
// class myservice auto-generated using wsdl.exe tool myservice service = new myservice(); requestmessage request = new requestmessage(); ... responsemessage response = service.getdata(request); ...
update:
here requestmessage class:
/// <remarks/> [system.codedom.compiler.generatedcodeattribute("svcutil", "3.0.4506.2152")] [system.serializableattribute()] [system.diagnostics.debuggerstepthroughattribute()] [system.componentmodel.designercategoryattribute("code")] [system.xml.serialization.xmltypeattribute(namespace="http://uri.etsi.org/02657/v1.5.1#/retaineddata")] public partial class requestmessage { private byte[] requestpriorityfield; private requestconstraints requestparametersfield; private string deliverypointhibfield; private string maxhitsfield; private nationalrequestparameters nationalrequestparametersfield; private system.xml.xmlelement anyfield; /// <remarks/> [system.xml.serialization.xmlelementattribute(datatype="hexbinary", order=0)] public byte[] requestpriority { { return this.requestpriorityfield; } set { this.requestpriorityfield = value; } } /// <remarks/> [system.xml.serialization.xmlelementattribute(order=1)] public requestconstraints requestparameters { { return this.requestparametersfield; } set { this.requestparametersfield = value; } } /// <remarks/> [system.xml.serialization.xmlelementattribute(order=2)] public string deliverypointhib { { return this.deliverypointhibfield; } set { this.deliverypointhibfield = value; } } /// <remarks/> [system.xml.serialization.xmlelementattribute(datatype="integer", order=3)] public string maxhits { { return this.maxhitsfield; } set { this.maxhitsfield = value; } } /// <remarks/> [system.xml.serialization.xmlelementattribute(order=4)] public nationalrequestparameters nationalrequestparameters { { return this.nationalrequestparametersfield; } set { this.nationalrequestparametersfield = value; } } /// <remarks/> [system.xml.serialization.xmlanyelementattribute(order=5)] public system.xml.xmlelement { { return this.anyfield; } set { this.anyfield = value; } } }
update #2:
the reason why java-based web service didn't c# client produced soap message not omission of namespace prefixes, because of omission of xmlns in getdata element, if message looks this:
... <getdata xmlns="http://a..."> ... </getdata> ...
it works!
i managed put xmlns inside getdata manually editing soaprpcmethodattribute in wsdl.exe-produced source code. here excerpt:
/// <remarks/> [system.codedom.compiler.generatedcodeattribute("wsdl", "2.0.50727.3038")] [system.diagnostics.debuggerstepthroughattribute()] [system.componentmodel.designercategoryattribute("code")] [system.web.services.webservicebindingattribute( name="axxxporttypebinding", namespace="http://a...")] public partial class axxxservice : system.web.services.protocols.soaphttpclientprotocol { ... /// <remarks/> [system.web.services.protocols.soaprpcmethodattribute( "http://a.../getdata", requestnamespace = "http://a...", responsenamespace = "http://a...", use = system.web.services.description.soapbindinguse.literal)] [return: system.xml.serialization.xmlelementattribute("response")] public responsemessage getdata(requestmessage request) { object[] results = this.invoke("getdata", new object[] { request}); return ((responsemessage)(results[0])); } ... }
before change, soaprpcmethodattribute had following constructor:
[system.web.services.protocols.soaprpcmethodattribute( "", requestnamespace = "", responsenamespace = "", use = system.web.services.description.soapbindinguse.literal)]
now, question is: put in wsdl file soaprpcmethodattribute have strings in constructor (filled wsdl.exe tool) in first place?
i've seen problem before wsdl.exe tool did not pull in namespace when generating service code. check request
object definition in generated code. guess there no xmlrootattribute
attribute defined on class definition request
object.
adding attribute [xmlrootattribute(namespace "http://a...")]
class definition request
object should fix issue.
as side note, recommend adding additional attribute in separate code file using partial class definition. defining attribute in separate file allow regenerate web service code using wsdl.exe whenever neccessary without overwriting fix set root element's namespace properly.
- Get link
- X
- Other Apps
Comments
Post a Comment