My customer wants to a web service for integration. They send me the documentation and I created a WCF Service with methods.
But there are namespaces and prefixs problem. I didn't find any solution and I didn't find any suggest. For example there is a different tag (
Customer will send request like this:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ws="http://ws.common.haciosman.com">
<soapenv:Header />
<soap:Body>
<ws:getSystemStatus/>
</soap:Body>
</soap:Envelope>
Customer wants to response like that:
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header/>
<soapenv:Body>
<ns:getSystemStatusResponse xmlns:ns="http://ws.common.haciosman.com">
<ns:return xsi:type="ax21:OutputMessage" xmlns:ax21="http://ws.common.haciosman.com/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ax21:code>200</ax21:code>
<ax21:description>Success</ax21:description>
</ns:return>
</ns:getSystemStatusResponse>
</soapenv:Body>
</soapenv:Envelope>
Okay, I created a service but namespace and prefix not match. My service response like that:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<getSystemStatusResponse>
<getSystemStatusResult xmlns:a="http://schemas.datacontract.org/2004/07/WCFLocal.cls" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:code>200</a:code>
<a:description>Success</a:description>
</getSystemStatusResult>
</getSystemStatusResponse>
</s:Body>
</s:Envelope>
As you see, tags are different. What is wrong and how can I change prefix in WCF Service?
Thanks for your reply.
Related
I created the service starting from a wsdl (copied locally).
The client created creates an xml that is not equal to what the service expects.
This is what should come out
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:iuv="http://dcod.xxxx.it/iuv/">
<soapenv:Header/>
<soapenv:Body>
<iuv:annullo>
<arg0>
<iuv>-1</iuv>
</arg0>
</iuv:annullo>
</soapenv:Body>
</soapenv:Envelope>
This is what the client produces
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<annullo xmlns="http://dcod.xxxx.it/iuv/">
<arg0>
<iuv>-1</iuv>
</arg0>
</annullo>
</s:Body>
</s:Envelope>
In particular
<annullo xmlns = "http://dcod.xxxx.it/iuv/">
it should become
<iuv:annullo>
What to change?
I have downloaded WsdlUI, a open source C# SOAP client that is able to consume and process WCF messages without needing to add a reference. I can post to a method that has simple types(like strings and ints). When the WCF method has a complex type the XML envelope is incorrect. I am somewhat a noob to WCF and am a little lost with all the code... someone please help; how do I get the XML to return the correct XML?
I enabled tracing on my server and here is the valid xml envelope from a console app that has the service reference added:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://host.com/BG.WCF/Service.svc</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/MobileInterface/CreateQueuedMsg</Action>
</s:Header>
<s:Body>
<CreateQueuedMsg xmlns="http://tempuri.org/">
<Token>add568d9-45e0-0000-98a5-762b84989797</Token>
<BGSMSMessage xmlns:a="http://schemas.datacontract.org/2004/07/BG.Bus.Mobile.Classes" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:BusinessID>Test</a:BusinessID>
<a:CommsGUID>eca403e7-1116-4bc3-a476-31e91c4ca33f</a:CommsGUID>
<a:DestinationAddress>+27000000000</a:DestinationAddress>
<a:Msg>test msg</a:Msg>
<a:MsgEncodingType>Default</a:MsgEncodingType>
<a:SendDT>2014-02-24T07:21:45.3187492+02:00</a:SendDT>
<a:SystemID>Test</a:SystemID>
<a:ValidityDT>2014-02-27T07:21:45.3187492+02:00</a:ValidityDT>
</BGSMSMessage>
<smsRoute xmlns:a="http://schemas.datacontract.org/2004/07/BG.Bus.Mobile.Classes" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:SMSRoute>BGWASP</a:SMSRoute>
</smsRoute>
</CreateQueuedMsg>
</s:Body>
here is the envelope WsdlUi returns:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://bgvm08mbl01.businessgenetics.co.za/BG.Bus/BG.Bus.Mobile.WCF/MobileService.svc</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/MobileInterface/CreateQueuedMsg</Action>
</s:Header>
<soap:Body>
<CreateQueuedMsg xmlns="http://tempuri.org/">
<Token>ADD568D9-45E0-498E-98A5-762B84989797</Token>
<BGSMSMessage>
<BusinessID>Test</BusinessID>
<CommsGUID>559eb322-7b01-438d-93f1-74b1aafccc4f</CommsGUID>
<DestinationAddress>0000000000</DestinationAddress>
<Msg>Testers2014-02-24 07:37:53</Msg>
<MsgEncodingType>Default</MsgEncodingType>
<SendDT>2014-02-24 07:37:53</SendDT>
<SystemID>Test</SystemID>
<ValidityDT>2014-02-27 07:37:53</ValidityDT>
</BGSMSMessage>
<smsRoute>
<SMSRoute>BGWASP</SMSRoute>
<SMSRoute>GV</SMSRoute>
</smsRoute>
</CreateQueuedMsg>
</soap:Body>
I am the developer of WsdlUI so thanks for using it.
The application currently does not work with complex types due to the bug that you are referring to.
I should have a release out mid June that will fix this problem.
Thanks for the detailed description of the problem in your post.
I have to send a SOAP fault message over HTTP to another web service if something goes wrong with a server, so I have this code:
<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>
<Response status="1">
<Description>DESC</Description>
<Errors>
<Error>500</Error>
</Errors>
</Response>
</soapenv:Body>
</soapenv:Envelope>
Is this a properly formatted SOAP fault message?
Is this a properly formatted SOAP fault message?
No it isn't. It should look something like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>...</faultcode>
<faultstring>...</faultstring>
<detail>...</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
The SOAP specification specifies what a fault is. Yours looks like an error result object of some sort which has some disadvantages as explained here for example.
Your WS framework should properly generate faults if you throw exceptions. If you are not using a framework but building the fault in some other way, then it must look like in my example above or it can't be called a SOAP fault.
Hey Bogdan I wrote this code and works like a charm!
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<soap:Fault>
<faultcode>500</faultcode>
<faultstring>SERVER ERROR</faultstring>
<detail>
<Response_status>1</Response_status>
<Description>DESCRIPTION</Description>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
But another question how to send a SOAP success message with a http code 200 an also I have to have some additional parameters in the message, this is a part of it
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<Response_status>0</Response_status>
<Description>SUCCESS</Description>
</soap:Body>
</soap:Envelope>
So with this also I have to send code 200, how to write that can I write it like this
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<soap:Fault>
<faultcode>200</faultcode>
<faultstring>OK</faultstring>
<detail>
<Response_status>0</Response_status>
<Description>SUCCESS</Description>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
I've got this WSDL(the service is not mine): http://soaptest.webapi-beta.gratka.pl/dom.html?wsdl
When I use WCF generated proxy the method tag in request soap message gets additional namespace definition like:
<q1:zaloguj xmlns:q1="http://soaptest.webapi-beta.gratka.pl/dom.html">
When I use PHP or proxy generated by wsdl.exe this doesn't happen.
I would like to ask, why does WCF do so, and is there possibility to change this behaviour (without using hand-made message modification in BeforeSendRequest)
Below I paste messages generated by PHP and WCF:
PHP one:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://soaptest.webapi-beta.gratka.pl/dom.html" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:zaloguj>
<login xsi:type="xsd:string">login</login>
<haslo xsi:type="xsd:string">password</haslo>
<klucz_webapi xsi:type="xsd:string">key</klucz_webapi>
<id_kategoria xsi:type="xsd:int">382a</id_kategoria>
<wersja_webapi xsi:type="xsd:int">2</wersja_webapi>
</ns1:zaloguj>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
WCF one:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<q1:zaloguj xmlns:q1="http://soaptest.webapi-beta.gratka.pl/dom.html">
<login xsi:type="xsd:string">login</login>
<haslo xsi:type="xsd:string">password</haslo>
<klucz_webapi xsi:type="xsd:string">key</klucz_webapi>
<id_kategoria xsi:type="xsd:int">382</id_kategoria>
<wersja_webapi xsi:type="xsd:int">2</wersja_webapi>
</q1:zaloguj>
</s:Body>
</s:Envelope>
Are you facing any issues? As far as xml is concerned, both are equivalent. PHP code is declaring the namespace (xmlns:ns1="http://soaptest.webapi-beta.gratka.pl/dom.html") at the root element while WCF is declaring at the point where it is needed - I would believe that this is what WSDL's implementation would be - does not seem to be anything wrong in it.
Is there a way to make a C#/.NET web service which normally produces XML like this
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<DHeader xmlns="http://www.abc.com" />
</soap:Header>
<soap:Body>
<Response xmlns="http://www.abc.com">
<Result>
<ErrorObject ObjectID="string" ErrorCode="" />
</Result>
</Response>
</soap:Body>
</soap:Envelope>
to produce XML like this.
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapv:Header>
<DHeader xmlns="http://www.abc.com" />
</soapenv:Header>
<soapenv:Body>
<Response xmlns="http://www.abc.com">
<Result>
<ErrorObject ObjectID="string" ErrorCode="" />
</Result>
</Response>
</soapenv:Body>
</soapenv:Envelope>
This trying solve a problem with an AXIS client consuming a .NET web service. AXIS is choking on the soap namespace and needs a soapenv namespace. Changing the AXIS side is not possible.
any thoughts or comments would be great.
Here is the exact error as requested.
line -1: Element Envelope#http://www.w3.org/2003/05/soap-envelope is not a valid Envelope#http://schemas.xmlsoap.org/soap/envelope/ document or a valid substitution.
soapenv is not a namespace - it's a namespace prefix.
As long as the prefixes refer to the same namespace, soap and soapenv refer to the same thing, and have the identical meaning.
It seems extremely unlikely that any version of AXIS is so badly broken as to treat the prefixes specially. You should assume you have a different problem. Please post the exact error you're receiving.