c# - Web Service returns SOAP but properties are empty -
i created web-service client, compiled wsdl, ok except empty properties after calling logon method (responsecode, etc. empty).
i have response soap message:
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sas="http://ws.test.com/"> <soapenv:header/> <soapenv:body> <sas:logonresponse> <sessionid>19790</sessionid> <responsecode>0</responsecode> <responsemessage>logon ok</responsemessage> </sas:logonresponse> </soapenv:body> </soapenv:envelope> the wsdl part method looks like:
<?xml version="1.0" encoding="utf-8"?> <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:sas="http://www.w3.org/2001/xmlschema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:tns="http://ws.test.com/" xmlns:ns="http://ws.test.com/" targetnamespace="http://ws.test.com/"> <wsdl:types> <sas:schema xmlns:sas="http://www.w3.org/2001/xmlschema" targetnamespace="http://ws.test.com/" elementformdefault="qualified"> <sas:element name="logon"> <sas:complextype> <sas:sequence> <sas:element name="username" type="sas:string" nillable="false"/> <sas:element name="password" type="sas:string" nillable="false"/> </sas:sequence> </sas:complextype> </sas:element> <sas:element name="logonresponse"> <sas:complextype> <sas:sequence> <sas:element name="sessionid" type="sas:long" nillable="false"/> <sas:element name="responsecode" type="sas:integer" nillable="false"/> <sas:element name="responsemessage" type="sas:string" nillable="false"/> </sas:sequence> </sas:complextype> </sas:element> </sas:schema> </wsdl:types> <wsdl:message name="logonrequest"> <wsdl:part name="logon" element="tns:logon"/> </wsdl:message> <wsdl:message name="logonresponse"> <wsdl:part name="logonresponse" element="tns:logonresponse"/> </wsdl:message> <wsdl:porttype name="rrrwebservice"> <wsdl:operation name="logon"> <wsdl:input message="tns:logonrequest"/> <wsdl:output message="tns:logonresponse"/> </wsdl:operation> </wsdl:porttype> <wsdl:binding name="mvcbinding" type="tns:rrrwebservice"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="logon"> <soap:operation soapaction="http://ws.test.com/logon" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="rrrwebservice"> <wsdl:port name="rrrwebservice" binding="tns:mvcbinding"> <soap:address location="http://172.6.2.14:8008/"/> </wsdl:port> </wsdl:service> </wsdl:definitions> can not figure out problem. compiled selecting "add service reference" in visual studio 2008. comments , answers appreciated! thanks.
the half-assed ms implementation picky format. wants ns:tag notation here
<?xml version="1.0" encoding="utf-8"?> <soap:envelope soap:encodingstyle="http://www.w3.org/2003/05/soap-encoding" xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <soap:body> <ns2:sessioncreateresponse xmlns:ns2="http://www.otrs.org/ticketconnector/"> <sessionid>3efvfynzxb2z8wukqrpevyc7k9jddalf</sessionid> </ns2:sessioncreateresponse> </soap:body> </soap:envelope> i have response app called otrs written in perl. created response this:
<soap:envelope soap:encodingstyle="http://www.w3.org/2003/05/soap-encoding" xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <soap:body> <sessioncreateresponse xmlns="http://www.otrs.org/ticketconnector/"> <sessionid>jufukqabresnemtcytphfilfwgjj4qnj</sessionid> </sessioncreateresponse> </soap:body> </soap:envelope> ms not have it. messing xmlschemaform.unqualified/none nothing. had hack in override in reference.cs reformat message.
protected override xmlreader getreaderformessage(soapclientmessage message, int buffersize) { var newstream = new memorystream(); var orgstream = message.stream; byte[] buf = new byte[buffersize]; orgstream.read(buf, 0, buffersize); string response = encoding.utf8.getstring(buf); int pos = response.indexof("response xmlns="); if (pos == -1) { pos = response.indexof("response>"); if (pos > -1) response = response.insert(pos + 8, " xmlns=\"http://tempuri.org/\""); } if (pos > -1) { int pos2 = pos + 8; int pos3 = pos + 14; while (response[--pos-1] != '<') ; string tagname = response.substring(pos, pos2 - pos); response = response.insert(pos3, ":ns2").insert(pos, "ns2:"); int pos4 = response.indexof("</" + tagname) + 2; response = response.insert(pos4, "ns2:"); } streamwriter sw = new streamwriter(newstream, encoding.utf8); sw.writeline(response); sw.flush(); newstream.position = 0; return new system.xml.xmltextreader(newstream); }
Comments
Post a Comment