Parsing WebClient SOAP response with extra stuff in body - web-services

I am trying to implement a reactive SOAP client using WebClient. My current implementation is based on https://github.com/gungor/spring-webclient-soap which uses org.springframework.ws.soap.saaj.SaajSoapMessageFactory to parse the response body into a SOAP object. My problem is that the createWebServiceMessage method can't parse the response body since it has extra data in it:
--uuid:0afe4a46-8bdd-471e-b17f-0079c5bd2f4b
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <root.message#cxf.apache.org>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
...
</soap:Body>
</soap:Envelope>
--uuid:0afe4a46-8bdd-471e-b17f-0079c5bd2f4b
The error that is thrown is Could not parse XML; nested exception is org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 1; Content is not allowed in prolog..
I understand that the uuid is some test thing and the rest is some "headers in body" thing but I don't understand how to configure SaajSoapMessageFactory (or any other MessageFactory so that it can parse the body. I have read every post on stack overflow regarding the uuid and the inline headers (and mtom) but I can't seem to apply it to my case.

Related

Power Bi Soap Request

I have a web service which uses soap actions to retrieve data. How can I add such a request to use inside Power BI. I tied Get Data from Web, but it seems I only can add request headers but no body.
POST /subtarget/SERVICE.asmx HTTP/1.1
Host: website.com
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://methods.org/GetProducts"
Content-Length: 559
<?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>
<GetProducts xmlns="http://tempuri.org/">
<username>name</username>
<password>pass</password>
<supplierId>313</supplierId>
</GetProducts>
</soap:Body>
</soap:Envelope>
You can add a body to Web.Contents as a second argument, using [Content = Body].
I have used http://dneonline.com/calculator.asmx to demonstrate, the request is quite simple, it will add two numbers.
Steps
Define your SOAP envelope inside your PowerQuery. Remove any unnecessary whitespaces, and transform single quotes " to double quotes "". Let's save this into a variable called SoapEnvelope.
Transform your SOAPEnvelope into binary using Text.ToBinary.
Construct the Web.Contents using Content with the the transformed SOAPEnvelope and the Header, in this case you only need #"Content-type" = 'text/xml'.
Wrap your Web.Contents into an XML content to display as Table.
let
SOAPEnvelope=
"<?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><Add xmlns=""http://tempuri.org/"">
<intA>1</intA>
<intB>2</intB></Add>
</soap:Body>
</soap:Envelope>",
Source = Xml.Document(
Web.Contents(
"http://dneonline.com/calculator.asmx",
[Content = Text.ToBinary(SOAPEnvelope), Headers = [#"Content-Type" = "text/xml"]]
)
)
in
Source

Delphi SOAP Request

I'm trying to send a SOAP Request to a webservice in Delphi XE5. Actually there is a WSDL available which I imported via WSDL Importer. I established a connection to this webservice with the components THTTPRIO (rio) and IdEncoderMIME1 for the HTTP Authentication Request.
The SOAP Request was build via TXMLDocument and has the following structure:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cod=NS_Codelist>
<soapenv:Header/>
<soapenv:Body>
<cod:GetLatestChangeDatesRequest>
<!--Zero or more repetitions:-->
<CodeListID>1035</CodeListID>
</cod:GetLatestChangeDatesRequest>
</soapenv:Body>
</soapenv:Envelope>
Furthermore I received the Porttype of the webservice.
codeserv:= GetCodeListPortType(true,'',rio);
These are methods from the WSDL:
codeserv.GetLatestChangeDates(const body:GetLatestChangeDatesRequestType):GetLatestChangeDatesResponseType
GetLatestChangeDatesRequestType = array of Int64;
GetLatestChangeDatesRequest = GetLatestChangeDatesRequestType;
GetLatestChangeDatesResponseType = array of CodeListLatestChangeDateType;
GetLatestChangeDatesResponse = GetLatestChangeDatesResponseType;
CodeListLatestChangeDateType
property CodeListID: Int64
property LatestChangeDate: TXSDate
I have already tried to set an array of Int64 for the parameter but then it says "element CodeListID is missing".
Unfortunately I don't find a way to send this XML SOAP Request to the webservice and to receive the response. Any ideas?
EDIT: I have tried to use the WSDL methods
var
codeserv: CodeListPortType;
arrIDs: GetLatestChangeDatesRequest;
response: GetLatestChangeDatesResponse;
begin
codeserv:= GetCodeListPortType(true,'',rio);
SetLength(arrIDs,1);
arrIDs[0]:= 1035;
response:= codeserv.GetLatestChangeDates(arrIDs);
But then I receive the following error message: 'invalid content was found starting with element 'long'. One of '{CodeListID}' is expected.'
In the SOAP Request there have to be the element CodeListID. Unfortunately it seems the method GetLatestChangeDates isn't creating the elements in the SOAP Request. The SOAP Request posted above should have been created with this method (hopefully).

Soapui property transfer to request header

I want to set the value of token in this soap ws header
<soapenv:Enveloppe ...
<soapenv:Header>
<web:token>123456 </web:token>
FROM step named test get idSession in response
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:authentification xmlns:ns1="http://ws.demowebservices.com/">
<bloc1>
<bloc2>
<idSession>e1c64cd9-b933-4f56-ae1f-0f7d7f23942b</idSession>
</bloc2>
I tried to put in-between web:token tag
${test#Response#//ns1:authentification/bloc1/bloc2/idSession}
but it does not work
What should I put instead ?
I'm not sure if this is what you're trying to achieve, however If you have a SOAP Test step called Test Request and you want to use the value of the <soapenv:Header><web:token></soapenv:Header> of this request in another SOAP Test step you can refer this value in the second SOAP Test step request using the follow syntax:
<soapenv:Enveloppe ...
<soapenv:Header>
<web:token>${Test Request#Request#//soapenv:Header/web:token}</web:token>
The syntax ${Test Request#Request#//soapenv:Header/web:token} has three parts, the name of the test step, followed by the property (could be #Request or #Response), and finally the xpath to get the value //soapenv:Header/web:token.
UPDATED:
As you said you've two SOAP Test Request, the first one is called test an has the follow response:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:authentification xmlns:ns1="http://ws.demowebservices.com/">
<bloc1>
<bloc2>
<idSession>e1c64cd9-b933-4f56-ae1f-0f7d7f23942b</idSession>
</bloc2>
</bloc1>
</ns1:authentification>
</soap:Body>
</soap:Envelope>
The second is named for example test 2 (don't care because the second name not affect your purpose) and has the follow request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<web:token>${test#Response#//ns1:authentification/bloc1/bloc2/idSession}</web:token>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
With ${test#Response#//ns1:authentification/bloc1/bloc2/idSession} you're referencing the idSession value of the test response correctly. Take a look on the http log tab when you send your test 2 as shown in the follow image:
Hope this helps,

Calling multiple WCF and asmx web services dynamically without generating proxy or using WSDL

We connect with multiple (20-30) third-party web services within our C# Batch Application. We are attempting to find the best way to call these web services dynamically (without generating proxy or using wsdl). All the third party agencies endpoints or URL's will be configured in database table. Client app will check the URL at run-time and make a service call. We are not worried about async calls it’s all synchronized process.
SQL Table : Client-configuration
Client URL Method IsActive
A http://serverhost/ClientA/Service1.svc Submit 1
B http://serverhost/ClientB/Service2.asmx Submit 1
The only issue is we are not sure about the third party service implementation is WCF or asmx. I have read few articles online to use HttpWebRequest to call web services dynamically (without generating proxies/wsdl.)
Is this the best way to implement this or any concerns I need to think of?
Please see below ex:
public static void CallWebService(string xml)
{
var _Url = "http://serverhost/ClientA/Service1.svc";
var _action = "http://serverhost/ClientA/Service1.svc/Submit";
try
{
ASCIIEncoding encoder = new ASCIIEncoding();
byte[] data = encoder.GetBytes(xml);
XmlDocument soapEnvelopeXml = CreateSoapEnvelope(xml);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(_Url);
webRequest.Headers.Add("SOAPAction", _action);
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.ContentLength = data.Length;
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
Stream webStream = webRequest.GetRequestStream();
webStream.Write(data, 0, data.Length);
webStream.Close();
WebResponse response = webRequest.GetResponse();
Stream responseStream = response.GetResponseStream();
using (StreamReader sr = new StreamReader(responseStream))
{
string s = sr.ReadToEnd();
}
}
catch (Exception ex)
{
responseStream = ex.Response.GetResponseStream();
}
}
Here is the details shared by one of the client.
http://setup.localhost.com/ClientA/Service1.asmx
Operation : Submit
SOAP 1.1
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be
replaced with actual values.
POST /ClientA/Service1.asmx HTTP/1.1
Host: setup.localhost.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://setup.localhost.com/Submit"
<?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>
<Submit xmlns="http://setup.localhost.com/">
<eCitXML>string</eCitXML>
<eCitPdf>base64Binary</eCitPdf>
<eCitKey>string</eCitKey>
</Submit>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<SubmitResponse xmlns="http://setup.localhost.com/">
<SubmitResult>string</SubmitResult>
</SubmitResponse>
</soap:Body>
</soap:Envelope>
SOAP 1.2
The following is a sample SOAP 1.2 request and response. The placeholders shown need to be
replaced with actual values.
POST /ClientA/Service1.asmx HTTP/1.1
Host: setup.localhost.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-
envelope">
<soap12:Body>
<Submit xmlns="http://setup.localhost.com/">
<eCitXML>string</eCitXML>
<eCitPdf>base64Binary</eCitPdf>
<eCitKey>string</eCitKey>
</Submit>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-
envelope">
<soap12:Body>
<SubmitResponse xmlns="http://setup.localhost.com/">
<SubmitResult>string</SubmitResult>
</SubmitResponse>
</soap12:Body>
</soap12:Envelope>
I think your question could be rephrased as
Is there a generic method to call any SOAP 1.1 or 1.2 web service operation without prior knowledge of the service operation except for the SOAP action and URL?
I'm assuming that all the third party web services expose a common operation which accepts and returns the same types.
If this is the case then providing you model the service operation contract correctly you could use ChannelFactory to call all the services.
Calling WCF services is straightforward in this manner, but to call asmx services you'd need to do a bit more work. So your client code would need to know if the service was asmx or wcf, and moreover, if wcf, whether the service is soap 1.1 or 1.2.
I must say I'm struggling to understand what advantage you will have once you have achieved this. I can see the value if you owned all the 20+ services you were calling, but this clearly is not the case.
Granted, you won't have a ton of nasty generated service reference code, but the whole point of WSDL is it allows for machine generated service contracts. If the third party services make any breaking changes you'll need to manually synchronize these inside your client code, rather than just regenerating the client.

How do I access SourceGear Web services using SOAP::Lite?

For some reason SourceGear provide an undocumented Web service on their installations. They actually ask developers to use the API instead because the Web service is kinda messy, but this is a problem in my case because I cannot use this API on a Perl environment, so their solution for my specific case is to use the Web service.
This shouldn't be a problem. Using SOAP::Lite I have connected to several Web services in the past in the same way. But the lack of documentation is a major chaos if you don't know where the SOAP calls can be made. I only have an XML to decipher where to and how to make these calls. It would be great if a real SOAP genius could help me out in this.
This is an example of the login call and the expected response:
Request
POST /fortress/dragnetwebservice.asmx HTTP/1.1
Host: velecloudserver
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.sourcegear.com/schemas/dragnet/LoginPlainText"
<?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>
<LoginPlainText xmlns="http://www.sourcegear.com/schemas/dragnet">
<strLogin>string</strLogin>
<strPassword>string</strPassword>
</LoginPlainText>
</soap:Body>
</soap:Envelope>
Response
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<LoginPlainTextResponse xmlns="http://www.sourcegear.com/schemas/dragnet">
<LoginPlainTextResult>int</LoginPlainTextResult>
<strAuthTicket>string</strAuthTicket>
</LoginPlainTextResponse>
</soap:Body>
</soap:Envelope>
I'm looking for a way to be able to assemble this somehow. This is my Perl example:
my $soap = SOAP::Lite -> uri ('http://velecloudserver/fortress/dragnetwebservice.asmx') -> proxy('http://velecloudserver/fortress/dragnetwebservice.asmx/LoginPlainText');
my $som = $soap->call('LoginPlainText', SOAP::Data->name('LoginPlainText')->value(
\SOAP::Data->value([
SOAP::Data->name('strLogin')->value( 'admin' ),
SOAP::Data->name('strPassword')->value('Adm1234'),
]))
);
Any tip would be appreciated.
Start by pointing wget/curl/lwp/etc. at http://velecloudserver/fortress/dragnetwebservice.asmx?WSDL
and see if you get a WSDL file back.
If you do, then compare it to the four types listed in the SOAP::Lite POD.
Your Request example looks like the Docment/Literal form, so you might end up writing something like this:
use SOAP::Lite;
my $soap = SOAP::Lite->new( file => 'http://velecloudserver/fortress/dragnetwebservice.asmx?WSDL');
$soap->on_action( sub { "urn:dragnetservice#LoginPlainText" });
$soap->autotype(0);
$soap->default_ns('urn:LoginPlainText');
my $som = $soap->call("LoginPlainText",
SOAP::Data->name('strLogin')->value( 'admin' ),
SOAP::Data->name('strPassword')->value('Adm1234'),
);
die $som->fault->{ faultstring } if ($som->fault);
print $som->result, "\n";
If you don't get WSDL back, I'd try replacing the constructor call with:
my $soap = SOAP::Lite->new( proxy => 'http://velecloudserver/fortress/dragnetwebservice.asmx');
The last time I worked with SOAP::Lite, I wrote a short program similar to the one above, and I ran it under the debugger. Before I executed the $soap->call() line, I peeked at the guts of the $soap object and looked at the request payload to see if the XML matched some working XML that I had by using the soapUI.org java client.
I had to read the POD a couple of times, and I dug into the source to figure our how some of the methods like default_ns() affected the generated XML. Once I did that, it all made a lot more sense.
Note: SOAP::Lite likes to die() when it fails. Wrap your calls in an eval{} for production use.