How to customize ASP.NET Websevices SOAP? - c#

I need a SOAP webservice can receive quest like
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:vas=" http://vasgate.mobifone.vn ">
<soapenv:Header/>
<soapenv:Body>
<vas:register>
<msisdn>904919419</msisdn>
<packagecode>PACK1</packagecode>
<username>kenh1</username>
<password>kenh#123</password>
<channel>wapportal</channel>
<info>khuyenmai</info>
</vas:register>
</soapenv:Body>
</soapenv:Envelope>
And can response like
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body >
<ns2: registerResponse xmlns:ns2="http://vasgate.mobifone.vn" >
<return>
<returncode>1</ returncode >
<returndesc>DANG_KY_THANH_CONG</returndesc>
<package>
<packagecode>PACK1</packagecode>
<cycle>1</cycle>
<price>1000</price>
<desc>sample package1</desc>
</package>
</return>
</ns2:registerResponse>
How to customize my webservice to do this?

Related

Move alias in xml created by SOAP Client (connected services)

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?

How change namespace and prefix in WCF

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.

Set custom tag in WSDL + WCF

Is possible to convert this fragment of wsdl:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://com.lsc.services.financialSystem">
<soapenv:Header/>
<soapenv:Body>
<com:crearCuentaPorCobrar>
<!--Optional:-->
<com:crearCuentaPorCobrarRq>
<com:infoRequest>
<com:RequestID>?</com:RequestID>
<com:Fecha>?</com:Fecha>
<com:AplicacionCliente>?</com:AplicacionCliente>
<com:Terminal>?</com:Terminal>
<com:IP>?</com:IP>
</com:infoRequest>
</com:crearCuentaPorCobrarRq>
</com:crearCuentaPorCobrar>
</soapenv:Body>
</soapenv:Envelope>
To this solution:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://com.lsc.services.financialSystem">
<soapenv:Header/>
<soapenv:Body>
<com:crearCuentaPorCobrar>
<!--Optional:-->
<crearCuentaPorCobrarRq>
<infoRequest>
<RequestID>?</com:RequestID>
<Fecha>?</com:Fecha>
<AplicacionCliente>?</com:AplicacionCliente>
<Terminal>?</com:Terminal>
<IP>?</com:IP>
</infoRequest>
</crearCuentaPorCobrarRq>
</com:crearCuentaPorCobrar>
</soapenv:Body>
</soapenv:Envelope>
You can observe that in the second WSDL I don't want to use the index: 'com' to its subitems, only in its container (crearCuentaPorCobrar). I observe another posts like: Controlling WCF response format and namespaces but this is not mi interest to establish more code on wsdl.
There is a way to build this???
Thk a lot!!!

SOAP fault message

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>

How to set up an untyped SOAP message + WSS in WCF?

soapUI creates a message to the service:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.is.shit.com">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-7" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>XXX</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XXX</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">aIFkEUMZyhKuzGobh3CRpg==</wsse:Nonce>
<wsu:Created>2011-09-20T09:33:11.545Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<body/>
</soapenv:Body>
</soapenv:Envelope>
tell me how this can be created in the WCF?
As I understand it uses the class Message. But as with his help to get such a request - I do not understand. Help please. Thank you.

Categories

Resources