SOAP Basics What To Do With Request - web-services

I am taking my first steps into SOAP and Web Services. I learn best by reverse engineering and reviewing existing code. (that and Dummies books).
I have the following SOAP request example from vendor that supplies XML data about their products. My problem, I don't know what to do with the code. (yes, I am that much of a newbie to this side of web development)
POST /exatawapi.asmx HTTP/1.1
Host: webapi.example.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://webapi.example.com/GetAvailableProductsXML"
<?xml version="1.0" encoding="utf-8"?>
<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:Body>
<GetAvailableProductsXML xmlns="http://webapi.example.com/">
<brand>All</brand>
</GetAvailableProductsXML>
</soap:Body>
</soap:Envelope>

YOu need to get hold of their WSDL. Then use this WSDL in your development environment to generate the classes. Look at the tutotials below for more detail.
A Java Tutorial
A C# Tutorial

Related

How to make SOAP Client for requests/responses in a C program

I have a C program that needs to send continuous requests and receive responses from a SOAP Server.
Shall I wrap the C program to in a C++ class and perform C# interface?
Or is there a way to code a C SOAP Client directly?
I have a custom HTTP headers to be included in the request.
Here is an example test from the SOAP Server documentation on how to call it but I can't figure out how to integrate it to my C program:
POST /otd HTTP/1.1
User-Agent: OT
Host: localhost:9002
Content-Length: 196
Connection: Close
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<doSome/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Basic Soap Request issue

I am very new to SOAP protocol.
I have this sample SOAP:
<?xml version="1.0" encoding="utf-8"?>
<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:Body>
<processSOAPReq xmlns="http://tempuri.org/">
<sRequest>string</sRequest>
<sResponse>string</sResponse>
</processSOAPReq>
</soap:Body>
</soap:Envelope>
I am given another xml with sample request. I have been trying to put this sample request inside the <sRequest>string</sRequest> above but I always get Bad Request or
server was unable to process request. ---> Value cannot be null. Parameter name: input
What am I doing wrong. I have been trying for a long time now using SOAPUI.
Btw I also have wsdl but I still do not understand what the correct request should be.
I would suggest that you check if the values are matching the parameters, and double check the wsdl file.

Consume SOAP web service using REST POST method

I want to consume a simple SOAP web service using REST technology. I've heard it can be achieved using POST method. Just adding some headers to the request. Is it possible? How to do that? Thanks a lot !!!
SOAP considers different information in the headers/body than REST does, but it's all HTTP:
# Headers
Content-Type: text/xml
SOAPAction: <SOAPAction here>
# Body
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<soapenv:Header>
.
</soapenv:Header>
<soapenv:Body>
.
.
.
</soapenv:Body>
</soapenv:Envelope>
You'll need to fill in the actual body with whatever the SOAP service expects (obviously) - that can be found in the WSDL if you don't have any sample requests available.
I found this blog post to be very helpful, even if you're making the call from some non-postman tool.

SOAP Web Service Auth Headers issue

I am currently trying to use a web service from a Flex client, and hitting a small issue. The service reads a SOAP header called 'AuthHeader' for credentials, and it works from a test client (using Storm from CodePlex) using this request:
<?xml version="1.0" encoding="utf-8"?>
<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>
<AuthHeader xmlns="http://ns.stickykiwi.com/">
<Username />
<Password />
</AuthHeader>
</soap:Header>
<soap:Body>
<Authenticate xmlns="http://ns.stickykiwi.com/" />
</soap:Body>
</soap:Envelope>
The service returns true (Boolean) if the credentials are ok, false if not. Now when I call the service from Flex it sends this:
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header>
<ns0:AuthHeader xmlns:ns0="https://stickykiwi01">
<ns0:Password/>
<ns0:Username/>
</ns0:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<tns:Authenticate xmlns:tns="http://ns.stickykiwi.com/"/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This returns,
'System.NullReferenceException: Object reference not set to an instance of an object'
because for some reason, probably best known to someone with better eyesight than me, there is a serious difference between these 2 requests, I am just not seeing it.
So, how do I create the headers in Flex? I have this code in the web service definition file:
var qname:QName = new QName("https://stickykiwi01","AuthHeader");
var header:SOAPHeader = new SOAPHeader(qname,{Username:"",Password:""});
_serviceControl.addHeader(header);
Which is in a file called _Super_AuthenticationServices.as. I pulled the Flex request from the network monitor.
A couple of points to note,
The service isn't mine, but I assume it works as I can test it from another client successfully.
Yes I know SOAP services are now depreciated and we should be moving all our code to WCF, it is in progress and will be brought in house eventually.
We wanted to use Basic auth for the service but Flex doesn't allow me to add the HTTP headers to a SOAP request so that is out.
All of this is run over HTTPS, because I know it is not secure as credentials are passed as plain text, once we have this running we will pass a single hashed string (same as basic auth) and unhash it on the server too, this way is just MUCH easier to debug.
Thank you for your advice.
EDIT
This is what the service is expecting, and I think I am meeting that criteria, I cannot see an issue here at all.
POST /services/_authentication/authenticationservices.asmx HTTP/1.1
Host: stickykiwi01
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://ns.stickykiwi.com/Authenticate"
<?xml version="1.0" encoding="utf-8"?>
<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>
<AuthHeader xmlns="http://ns.stickykiwi.com/">
<Username>string</Username>
<Password>string</Password>
</AuthHeader>
</soap:Header>
<soap:Body>
<Authenticate xmlns="http://ns.stickykiwi.com/" />
</soap:Body>
</soap:Envelope>
No, it works.
Not sure what was going on, but I changed nothing, but this morning the headers are working exactly as expected, here is the request
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header>
<tns:AuthHeader xmlns:tns="http://ns.stickykiwi.com/">
<tns:Username></tns:Username>
<tns:Password></tns:Password>
</tns:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<tns:Authenticate xmlns:tns="http://ns.stickykiwi.com/"/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The only difference I can see is that now the prefix is tns on everything instead of ns0. But anyway, issue resolved, possibly via magic.
Thanks

calling Axis2 web service from ATL C++ client

I have a simple POJO web service published with Axis2 on Tomcat5.5
I try to consume it with ATL C++ client and it fails. Doing the same with a C# client works.
The problem is that ATL client sends soap body which looks like
<soap:Body>< xmlns="http://fa.test.com/xsd"></></soap:Body></soap:Envelope>
Notice the invalid element in the middle.
I suspect it has something to do with UTF-8 because C# sends a header of
<?xml version='1.0' encoding='utf-8'?>
and ATL client doesn't. Also when I look into some of the ATL SOAP internals I notice that a structure has two members: szName and szwName. The first one is empty and produces the element, the second one has a valid (?) name of testResponse (the method I'm calling is called "test").
Need advice as to where to go from here?
More details:
full message from ATL client:
POST /axis2/services/EnterpriseService.EnterpriseServiceHttpSoap11Endpoint/ HTTP/1.1
Content-Length: 304
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:test"
Accept: text/xml
Host: xxxxxxx
User-Agent: Microsoft-ATL-Native/8.00
<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:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><soap:Body>< xmlns="http://fa.test.com/xsd"></></soap:Body></soap:Envelope>
Response from Axis2:
HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=utf-8
Transfer-Encoding: chunked
Date: Tue, 04 Nov 2008 15:31:57 GMT
Connection: close
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server</faultcode><faultstring>com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '>' (code 62); expected an element name.
at [row,col {unknown-source}]: [1,276]</faultstring><detail /></soapenv:Fault></soapenv:Body></soapenv:Envelope>
Oh, and here is the good request coming from C# client:
POST /axis2/services/EnterpriseService.EnterpriseServiceHttpSoap11Endpoint/ HTTP/1.1
Via: 1.1 ANGEL-ISLAND
Content-Type: text/xml; charset=utf-8
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.1433)
Host: xxxxxxx:8080
SOAPAction: "urn:test"
Connection: Keep-Alive
Content-Length: 236
<?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 /></soap:Envelope>
In C# case the soap:body is blank.
ATL Server is entirely capable of generating the request correctly. Looks like there's some issue with the WSDL. My cursory test generates the request:
<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:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body></soap:Body></soap:Envelope>
for an ASP.NET Web service with SoapParameterStyle.Bare. Do you have a <wsdl:part> element in the input message? Can you post the WSDL service description?
I don't think it has anything to do with UTF-8.
The valid message from C# doesn't have anything inside the soap:Body, while the invalid message has . It looks like the ATL C++ client is trying to force something inside the SOAP body when there shouldn't be anything there at all.
Note also that the C# client doesn't include a testResponse element in its message.
I'd look the code some more where it uses szName and see if that's where it's generating the . It shouldn't be doing that.