SOAPpy, C# and object passing - c#

I'm trying to write a SOAPpy client to my C# WebService. It is arriving as null :(
How can I get any debug from the C# SOAP parser that WebService uses?
This is what Python sends:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
>
<SOAP-ENV:Body>
<ns1:UpdateSession xmlns:ns1="http://www.xlogic.pl/SENACA" SOAP-ENC:root="1">
<xsd:Session>
<ID xsi:type="xsd:int">420</ID>
<RecordCreationTime SOAP-ENC:arrayType="xsd:ur-type[6]" xsi:type="SOAP-ENC:Array">
<item xsi:type="xsd:int">2010</item>
<item xsi:type="xsd:int">8</item>
<item xsi:type="xsd:int">17</item>
<item xsi:type="xsd:int">11</item>
<item xsi:type="xsd:int">13</item>
<item xsi:type="xsd:double">21.0</item>
</RecordCreationTime>
<ASP_SessionID xsi:type="xsd:string">92072674A04CB88D62776EA7</ASP_SessionID>
<LangID xsi:type="xsd:string">fr-FR</LangID>
<OneTimeKey xsi:type="xsd:string">a334cea18e014f4d8d04</OneTimeKey>
</xsd:Session>
</ns1:UpdateSession>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This is what C# expects
<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="http://www.xlogic.pl/SENACA"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<tns:UpdateSession>
<s href="#id1"/>
</tns:UpdateSession>
<tns:Session id="id1" xsi:type="tns:Session">
<ID xsi:type="xsd:int">int</ID>
<RecordCreationTime
xsi:type="xsd:dateTime">dateTime</RecordCreationTime>
<ASP_SessionID xsi:type="xsd:string">string</ASP_SessionID>
<LangID xsi:type="xsd:string">string</LangID>
<OneTimeKey xsi:type="xsd:string">string</OneTimeKey>
</tns:Session>
</soap:Body>
</soap:Envelope>

Not a Python answer, but soapUI is a very useful facility for debugging and automated testing of web services. I used it heavily on a C# WCF project, with a variety of clients, including Python, Boo, Java, and C#.

Related

remove namespaces, attributes, Xsi from Soap response using code or XSLT

Remove namespaces, attributes, Xsi from Soap response using code or XSLT
Want to transform a soap response to a normal XML(without namespaces, atributes) using C# code (Serializer, XMLDoc, XDoc ) or XSLT.
here is the soap response.
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="urn:Magento"
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:catalogProductInfoResponse>
<info xsi:type="ns1:catalogProductReturnEntity">
<product_id xsi:type="xsd:string">3459</product_id>
<sku xsi:type="xsd:string">HK-BP001</sku>
<categories SOAP-ENC:arrayType="xsd:string[0]" xsi:type="ns1:ArrayOfString"/>
<websites SOAP-ENC:arrayType="xsd:string[7]" xsi:type="ns1:ArrayOfString">
<item xsi:type="xsd:string">1</item>
</websites>
<created_at xsi:type="xsd:string">2016-04-19 01:45:35</created_at>
<has_options xsi:type="xsd:string">1</has_options>
<special_from_date xsi:type="xsd:string">2016-04-19 00:00:00</special_from_date>
<tier_price SOAP-ENC:arrayType="ns1:catalogProductTierPriceEntity[0]" xsi:type="ns1:catalogProductTierPriceEntityArray"/>
<custom_design xsi:type="xsd:string">ultimo/default</custom_design>
<enable_googlecheckout xsi:type="xsd:string">1</enable_googlecheckout>
</info>
</ns1:catalogProductInfoResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
i want transformed xml like :
<?xml version="1.0" encoding="UTF-8"?>
<Envelope>
<Body>
<catalogProductInfoResponse>
<info>
<product_id>3459</product_id>
<sku>HK-BP001</sku>
<categories/>
<websites>
<item>1</item>
</websites>
<created_at>2016-04-19 01:45:35</created_at>
<has_options>1</has_options>
<special_from_date>2016-04-19 00:00:00</special_from_date>
<tier_price/>
<custom_design>ultimo/default</custom_design>
<enable_googlecheckout>1</enable_googlecheckout>
</info>
</catalogProductInfoResponse>
</Body>
</Envelope>
You can use XSLT:
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

missing prefix in soap request c# dynamic web request

I´m using the WsdlImporter to read a wsdl-file and create a dynamic web request. But if I create the request a prefix in my request is missing and the consuming web service can not handle with this request. How can I force, that the prefix will be set?
This is how the request should be:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:urn="urn:sap-com:document:sap:rfc:functions>
<soap:Body>
<urn:K23G_GET_COST_ELEMENTS>
<ID_BEKNZ xmlns="">S</ID_BEKNZ>
<ID_COLLECT_MESSAGES xmlns="">X</ID_COLLECT_MESSAGES>
<ID_GJAHR xmlns="">2016</ID_GJAHR>
<ID_KOKRS xmlns="">K001</ID_KOKRS>
<ID_VERSN xmlns="">000</ID_VERSN>
<ID_WRTTP xmlns="">04</ID_WRTTP>
<ET_MESG xmlns="">
<item />
</ET_MESG>
<ET_RESULTS xmlns="">
<item />
</ET_RESULTS>
<IT_COSEL_KSTAR xmlns="">
<item />
</IT_COSEL_KSTAR>
<IT_COSEL_OBJ xmlns="">
<item />
</IT_COSEL_OBJ>
</urn:K23G_GET_COST_ELEMENTS>
</soap:Body>
</soap:Envelope>
An this is how the request looks like:
The urn before K23G_GET_COST_ELEMENTS is missing
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<K23G_GET_COST_ELEMENTS xmlns:urn="urn:sap-com:document:sap:rfc:functions>
<ID_BEKNZ xmlns="">S</ID_BEKNZ>
<ID_COLLECT_MESSAGES xmlns="">X</ID_COLLECT_MESSAGES>
<ID_GJAHR xmlns="">2016</ID_GJAHR>
<ID_KOKRS xmlns="">K001</ID_KOKRS>
<ID_VERSN xmlns="">000</ID_VERSN>
<ID_WRTTP xmlns="">04</ID_WRTTP>
<ET_MESG xmlns="">
<item />
</ET_MESG>
<ET_RESULTS xmlns="">
<item />
</ET_RESULTS>
<IT_COSEL_KSTAR xmlns="">
<item />
</IT_COSEL_KSTAR>
<IT_COSEL_OBJ xmlns="">
<item />
</IT_COSEL_OBJ>
</urn:K23G_GET_COST_ELEMENTS>
</soap:Body>
</soap:Envelope>
Somebody there who can help me?
Thank you

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>

soap service The specified type was not recognized

Can anyone tell me why I get:
{"The specified type was not recognized: name='anyType', namespace='http://www.mywebsite.com/webservice/service.wsdl', at <response xmlns=''>."}
And the xml that I'm getting is:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.mywebsite.com/webservice/service.wsdl" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<SOAP-ENV:getCarsResponse>
<response SOAP-ENC:arrayType="ns1:anyType[2]" xsi:type="ns1:carlist">
<item xsi:type="SOAP-ENC:Struct">
<id xsi:type="xsd:string">1392</id>
<merk xsi:type="xsd:string">Citroen</merk>
<type xsi:type="xsd:string">C1</type>
<uitvoering xsi:type="xsd:string">1.0i Selection 5D</uitvoering>
<leaseprijs xsi:type="xsd:string">299,--</leaseprijs>
<looptijd xsi:type="xsd:string">18</looptijd>
<kilometrage xsi:type="xsd:string">25.000</kilometrage>
<thumbnail xsi:type="xsd:string">/i_upload/free/_th.gif</thumbnail>
</item>
<item xsi:type="SOAP-ENC:Struct">
<id xsi:type="xsd:string">1393</id>
<merk xsi:type="xsd:string">Citroen</merk>
<type xsi:type="xsd:string">C1</type>
<uitvoering xsi:type="xsd:string">1.0i Selection 5D</uitvoering>
<leaseprijs xsi:type="xsd:string">299,--</leaseprijs>
<looptijd xsi:type="xsd:string">18</looptijd>
<kilometrage xsi:type="xsd:string">25.000</kilometrage>
<thumbnail xsi:type="xsd:string">/i_upload/free/_th.gif</thumbnail>
</item>
</response>
</SOAP-ENV:getCarsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I invoke the SOAP service in this way:
Service.service_portClient proxy = new Service.service_portClient();
proxy.getCars("Citroen", benzine);

Implement WS-Addressing in a C# DotNet Web Service

I'm building a Web Service in C# with VS2008, and want to implement WS-Addressing, so the message headers look like eg below:
What do I need to add / do in VS2008 to make this happen?
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://www.w3.org/2005/08/addressing"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wsssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
<soap:Header>
<wsa:To>http://messagehandler.org.com/sendmessage</wsa:To>
<wsa:ReferenceParameters>
</wsa:ReferenceParameters>
<wsa:From>
<wsa:EndpointReference>
<wsa:Address>http://www.thirdparty.com/address</wsa:Address>
</wsa:EndpointReference>
</wsa:From>
<wsa:Action>http://www.org.com/ServiceName</wsa:Action>
<wsa:MessageID>urn:uuid:18367C02-8286-487b-9D35-D2EDC974ACF8</wsa:MessageID>
<wsa:RelatesTo>urn:uuid:346CC216-5C14-496d-B6EA-7B644CAF6D48</wsa:RelatesTo>
<wsse:Security>
</wsse:Security>
</soap:Header>

Categories

Resources