SOAP Web Service Auth Headers issue - web-services

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

Related

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.

call webservice url with credentials

I know this is a bad idea since everyone can see the credentials but this is going to happen from a stored procedure so it is pretty secure anyway. I just want to call the webservice GetPerson method and send in SSN, username and password
http://79.171.249.41/nasherpopman/PopManWebService.asmx/GetPerson?personnumber=197310101212&username=myusername&password=mypassword
But when i do this the page goes blank and the only thing on the page is:
Index was outside the bounds of the array.
and i get 500 Internal Server Error if i go to chrome developer bar under network and look at the call. Do i have to send the credentials to the method in another way?
this is what the webservice method looks like:
<?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>
<GetPerson xmlns="http://tempuri.org/">
<personnumber>string</personnumber>
<username>string</username>
<password>string</password>
</GetPerson>
</soap:Body>
</soap:Envelope>

SOAP Basics What To Do With Request

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

gSOAP web service respond without namespace

I'm implementing client web service from .wsdl in C++ using gSOAP library.
And i have a problem, i see in tcpdump data exchange like this:
REQUEST
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://tempuri.org/" xmlns:ns2="http://xxx.pl/">
<SOAP-ENV:Body>
<ns1:AuthenticateUserRequest>
<ns1:login>xxxx</ns1:login>
<ns1:password>xxxx</ns1:password>
</ns1:AuthenticateUserRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
RESPONSE
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<authenticate>
<token>xxxx</token>
<server>xxxx</server>
</authenticate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But gSOAP don't like respond without namespace (ns1 is a namespace from wsdl what i implementing) and throws me error.
SOAP 1.1 fault: SOAP-ENV:Client[no subcode]
"Validation constraint violation: tag name or namespace mismatch in element 'authenticate'"
Detail: [no detail]
What i can do with that to fix this namespace issues?
Thanks for help!
You should be able to give gSOAP a default namespace to use durring parsing of the responce.
See if this link helps:
http://cateof.wordpress.com/2010/09/21/default-namespace-gsoap-with/

How to call an asynchronous BPEL process?

I've got an asynchronous BPEL process and I wanna call it from my Java EE web application. How can I do this? I'm using Oracle SOA-Suite 11g PS3.
An Asynchronous SOAP/HTTP sender is basically the same as a Synchronous SOAP/HTTP client, just it throws away the response. Only check the HTTP status of the response to verify that the receiver understood your message.
An Asynchronous receiver is basically a SOAP/HTTP server listening on the address sent in the "ReplyTo/Adress" field of the request. After receiving the message it sends an empty response with a "200" status code.
The sent and received messages are correlated using the WS-Addressing SOAP header fields "MessageID" (request) and "RelatesTo" (response).
If you are happy with a "low-tech" solution, you can send/receive Asynch SOAP requests just as XML over HTTP. The following HTTP Request will be understood by the BPEL process "AsynchDummy" as an asynchronous request. AsynchDummy is the default asynchronous BPEL process generated with JDeveloper:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" env:encodingStyle="">
<env:Header>
<ReplyTo xmlns="http://schemas.xmlsoap.org/ws/2003/03/addressing">
<Address>http://localhost:3333/my/j2ee/servlet</Address>
<PortType xmlns:ptns="http://xmlns.oracle.com/AsynchDummy">ptns:AsynchDummyCallback</PortType>
<ServiceName xmlns:snns="http://xmlns.oracle.com/AsynchDummy">snns:AsynchDummyCallbackService</ServiceName>
</ReplyTo>
<MessageID xmlns="http://schemas.xmlsoap.org/ws/2003/03/addressing" ans1:rootId="610005" xmlns:ans1="http://schemas.oracle.com/bpel" ans1:parentId="160005" ans1:priority="0">ABC123</MessageID>
</env:Header>
<env:Body>
<AsynchDummyProcessRequest xmlns="http://xmlns.oracle.com/AsynchDummy">
<input>this is the request</input>
</AsynchDummyProcessRequest>
</env:Body>
</env:Envelope>
Don't forget to set the SOAPAction HTTP header to "initiate" (including the quotation marks).
You can expect a similar message from the callback client step of the BPEL process:
<?xml version="1.0" encoding="UTF-8"?>
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:add="http://schemas.xmlsoap.org/ws/2003/03/addressing" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<add:RelatesTo>ABC123</add:RelatesTo>
<add:MessageID ans1:rootId="" ans1:parentId="" ans1:priority="0" xmlns:ans1="http://schemas.oracle.com/bpel">ABC456</add:MessageID>
</soap-env:Header>
<soap-env:Body>
<AsynchDummyProcessResponse xmlns="http://xmlns.oracle.com/AsynchDummy">
<result>this is the result</result>
</AsynchDummyProcessResponse>
</soap-env:Body>
</soap-env:Envelope>