Building SOAP request from WSDL - web-services

I need to execute a SOAP request to an external server. I have never worked with SOAP before, but I know the basics of REST.
I've been given this following WSDL file and this example query:
<Messages>
<Version Ds_Version="0.0">
<Message>
<Detail>
<Ds_MerchantCode>999008881</Ds_MerchantCode>
<Ds_Terminal>1</Ds_Terminal>
<Ds_Order>5799L</Ds_Order>
<Ds_TransactionType>3</Ds_TransactionType>
</Detail>
</Message>
</Version>
<Signature>UfECD0KD9Wwo1iqY6PYZoJxw8KwMUz8m18bgLyH3BCI=</Signature>
<SignatureVersion>HMAC_SHA256_V1</SignatureVersion>
</Messages>
I'm using Postman in order to test the API. Following some instructions I found on the internet, I added a Content-Type HTTP header with value text/xml and the SOAPAction HTTP header with value consultaOperaciones as found in the WSDL file.
I've set this body:
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body xmlns:m="http://webservices.apl02.redsys.es">
<m:consultaOperacionesRequest>
<Messages>
<Version Ds_Version="0.0">
<Message>
<Transaction>
<Ds_MerchantCode>999008881</Ds_MerchantCode>
<Ds_Terminal>1</Ds_Terminal>
<Ds_Order>5799L</Ds_Order>
<Ds_TransactionType>3</Ds_TransactionType>
</Transaction>
</Message>
</Version>
<Signature>1KoxTgTakbTprzJ2N/e9JJ8yw/C3QzeNafbUMCNGSFM=</Signature>
<SignatureVersion>HMAC_SHA256_V1</SignatureVersion>
</Messages>
</m:consultaOperacionesRequest>
</soap:Body>
</soap:Envelope>
However, when I send the request I receive the following error message:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<soapenv:Fault>
<faultcode>Server</faultcode>
<faultstring>Internal Error</faultstring>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
It's a generic SOAP error message, therefore I think that the problem has to be related to the codification instead of the external service.
Thanks in advance.

In the WSDL file you will see that the XML should be sent as a string:
<element name="consultaOperaciones">
<complexType>
<sequence>
<element name="cadenaXML" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
</element>
Hence the XML sent should be:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices.apl02.redsys.es">
<soapenv:Header/>
<soapenv:Body>
<web:consultaOperaciones>
<cadenaXML><![CDATA[
<Messages>
<Version Ds_Version="0.0">
<Message>
<Detail>
<Ds_MerchantCode>999008881</Ds_MerchantCode>
<Ds_Terminal>1</Ds_Terminal>
<Ds_Order>5799L</Ds_Order>
<Ds_TransactionType>3</Ds_TransactionType>
</Detail>
</Message>
</Version>
<Signature>UfECD0KD9Wwo1iqY6PYZoJxw8KwMUz8m18bgLyH3BCI=</Signature>
<SignatureVersion>HMAC_SHA256_V1</SignatureVersion>
</Messages>
]]>
</cadenaXML>
</web:consultaOperaciones>
</soapenv:Body>
</soapenv:Envelope>
Note that we are using CDATA because as mentioned the XML message should be sent as a string based on the WSDL. I have tried running it and got the response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<p259:consultaOperacionesResponse xmlns:p259="http://webservices.apl02.redsys.es">
<consultaOperacionesReturn><![CDATA[<Messages><Version Ds_Version="0.0"><Message><ErrorMsg><Ds_ErrorCode>XML0023</Ds_ErrorCode></ErrorMsg></Message></Version></Messages>]]></consultaOperacionesReturn>
</p259:consultaOperacionesResponse>
</soapenv:Body>
</soapenv:Envelope>
This means that your message is being parsed now because there are no server errors and a consultaOperacionesResponse is being sent which looks legit. The error seems to be related to the data being sent but in general the API is working fine as expected.

Related

SOAP namespace change axis

I want to host a web-service which will return a response of
<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>
<QcB2BQNBPaymentIntegrationBalUpdatePaymentPostingResponse xmlns="http://tempuri.org">
<response xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<b:string>QCP-0031312;158155421123</b:string>
</response>
</QcB2BQNBPaymentIntegrationBalUpdatePaymentPostingResponse>
</soapenv:Body>
</soapenv:Envelope>
but I am getting the response as
<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>
<QcB2BQNBPaymentIntegrationBalUpdatePaymentPostingResponse xmlns="http://tempuri.org">
<response >
<ns1:string xmlns:ns1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">QCP-0031312;158155421123</ns1:string>
</response>
</QcB2BQNBPaymentIntegrationBalUpdatePaymentPostingResponse>
</soapenv:Body>
</soapenv:Envelope>
I want to get the former response. please share some insight.
note: I've generated the java bean skeleton using axis

Mule http request returns complete soap message

Below http:outbound-endpoint returns the expected response as CDATA but when i change it to http:request it returns the whole SOAP message instead of just CDATA. I don't want to write any custom code to extract the CDATA.
Any help is appreciated!
Flow works with http:outbound-endpoint:
<flow name="Client">
<logger message="REQUEST : #[payload]" level="WARN"/>
<http:outbound-endpoint exchange-pattern="request-response" address="http://server:8080/RoomStatusService/webservices.asmx" >
<cxf:jaxws-client clientClass="com.test.webservices.WebServices" operation="UpdateRoomStatus" port="WebServicesSoap" />
</http:outbound-endpoint>
<logger message="RESPONSE : #[payload]" level="WARN"/>
</flow>
Expected Response:
REQUEST : <?xml version="1.0" encoding="UTF-8" standalone="yes"?><RoomStatusDetail><InspBy>AUTO</InspBy><RoomNumber>402</RoomNumber><RoomStatus>3</RoomStatus><Wing>ST</Wing></RoomStatusDetail>
RESPONSE : <UpdateRoomStatusResult><RoomStatusDetail>Room updated.</RoomStatusDetail></UpdateRoomStatusResult>
Flow doesn't work with http:request:
<http:request-config name="CONFIG" host="server" port="8080" doc:name="HTTP Request Configuration"/>
<flow name="Client">
<logger message="REQUEST : #[payload]" level="WARN"/>
<cxf:jaxws-client clientClass="com.test.webservices.WebServices" operation="UpdateRoomStatus" port="WebServicesSoap" />
<http:request config-ref="CONFIG" path="RoomStatusService/webservices.asmx" method="POST" doc:name="HTTP" >
<http:success-status-code-validator values="0..599"/>
</http:request>
<logger message="RESPONSE : #[payload]" level="WARN"/>
</flow>
Incorrect Response:
REQUEST : <?xml version="1.0" encoding="UTF-8" standalone="yes"?><RoomStatusDetail><InspBy>AUTO</InspBy><RoomNumber>402</RoomNumber><RoomStatus>3</RoomStatus><Wing>ST</Wing></RoomStatusDetail>
RESPONSE : <?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><UpdateRoomStatusResponse xmlns="http://testsoftware.com/webservices/"><UpdateRoomStatusResult><UpdateRoomStatusResult><RoomStatusDetail>Room updated.</RoomStatusDetail></UpdateRoomStatusResult></UpdateRoomStatusResult></UpdateRoomStatusResponse></soap:Body></soap:Envelope>
Sample Request & Response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://testsoftware.com/webservices/">
<soapenv:Header/>
<soapenv:Body>
<web:UpdateRoomStatus>
<web:UpdateRoomStatusRequest><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?><RoomStatusDetail><Wing>ET</Wing><RoomNumber>50102</RoomNumber><RoomStatus>1</RoomStatus><InspBy>test</InspBy></RoomStatusDetail>]]></web:UpdateRoomStatusRequest>
</web:UpdateRoomStatus>
</soapenv:Body>
</soapenv:Envelope>
<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>
<UpdateRoomStatusResponse xmlns="http://testsoftware.com/webservices/">
<UpdateRoomStatusResult><UpdateRoomStatusResult><RoomStatusDetail>Room updated.</RoomStatusDetail></UpdateRoomStatusResult></UpdateRoomStatusResult>
</UpdateRoomStatusResponse>
</soap:Body>
</soap:Envelope>
http:outbound is not doing anything but it is the tag which removes the SOAP envelope around the response. If you are consuming SOAP web service, better use Web service consumer.
You can use replace function to remove soap envelope like as below.Once you receive the payload ,use Set payload :
#[message.payloadAs(String).replace('<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>
<UpdateRoomStatusResponse xmlns="http://testsoftware.com/webservices/">','')]
and again use replace function to remove end part of Soap envelope and then pretty print the response
<mulexml:xml-prettyprinter-transformer xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" newlines="false" indentEnabled="false" padText="false" trimText="true"/>

SoapUI doesnt give correct response compared with written java program in netbeans

I am new to webservices ,
wsdl link : http://pp.hotels.travelrepublic.co.uk/ChannelManager.svc?wsdl
I have a wsdl url, easily in netbeans i have created and used.
Input via netbeans to webservice :
I am Sending the Request via java Program in netbeans request is:
<Request><Authentication CMId='68' Guid='5594FB83-F4D4-431F-B3C5-EA6D7A8BA795' Password='poihg321TR' Function='1' /><Establishment Id='4297867' > </Establishment></Request>
the response is :
<Response>
<Authentication CMId="68" Guid="5594FB83-F4D4-431F-B3C5-EA6D7A8BA795" Password="poihg321TR" Function="1" />
<Establishment Id="4297867">
<RoomTypes>
<RoomType RoomTypeId="1040459" Description="Double Room" />
<RoomType RoomTypeId="1040458" Description="Single Room" />
</RoomTypes>
<BoardTypes>
<BoardType BoardTypeId="1" Description="Room Only" />
</BoardTypes>
with the help of SoapUI
request generated is
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:RequestData>
<!--Optional:-->
<tem:requestDocument xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</tem:RequestData>
</soapenv:Body>
</soapenv:Envelope>
What i am sending through SoapUI is
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:RequestData>
<!--Optional:-->
<tem:requestDocument xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<!--The data sent via java program:-->
<Request>
<Authentication CMId='68' Guid='5594FB83-F4D4-431F-B3C5-EA6D7A8BA795' Password='poihg321TR' Function='1' />
<Establishment Id='4297867' >
</Establishment>
</Request>
<!--The data sent via java program:-->
</tem:RequestData>
</soapenv:Body>
</soapenv:Envelope>
If I run this in SoapUI
Output is not same as
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<RequestDataResponse xmlns="http://tempuri.org/">
<RequestDataResult><Response Error="Unable to parse xml">
<RequestDate Date="2014-05-30 16:14:15.7383" />
</Response></RequestDataResult>
</RequestDataResponse>
</s:Body>
</s:Envelope>
Try:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:RequestData>
<!--Optional:-->
<tem:requestDocument>
<![CDATA[<Request>
<Authentication CMId="68" Guid="5594FB83-F4D4-431F-B3C5-EA6D7A8BA795" Password="poihg321TR" Function="1"/>
<Establishment Id="4297867"></Establishment>
</Request>]]>
</tem:requestDocument>
</tem:RequestData>
</soapenv:Body>
</soapenv:Envelope>
Essentially, the WSDL does not have any of the Request and Authentication and other stuff defined, so you cannot send that. Further, the response tells you: "Unable to parse xml", so the application (as opposed to the service) is looking for XML data.

Apache CXF:The message has expired

Environment :
Apache CXF 2.7.8
Jboss EAP 6
SoapUI for testing client Side
I tried to implement for simple authentication i.e with password simple text type, it is working but when i tried to implement for password digest type ,then giving me exception:
unwinding now: org.apache.cxf.binding.soap.SoapFault: The message has
expired org.apache.ws.security.WSSecurityException: The message has
expired
I am giving new nonce value for each request and time within five min diff
WSS4JInInterceptor Bean class defination:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="orderProcess" implementor="demo.order.OrderProcessImpl" address="/OrderProcess" >
<jaxws:inInterceptors>
<bean
class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
<constructor-arg>
<map>
<entry key="action" value="UsernameToken"/>
<entry key="passwordType" value="PasswordDigest"/>
<entry key="passwordCallbackRef" value-ref="myPasswordCallback"/>
</map>
</constructor-arg>
</bean>
</jaxws:inInterceptors>
</jaxws:endpoint>
<bean id="myPasswordCallback" class="service.ServerPasswordCallback" />
</beans>
Client xml request Code:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ord="http://order.demo/"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soapenv:Header>
<wsse:Security>
<wsse:UsernameToken>
<wsse:Username>joe</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">PE7F51/oyWFVMsiZURuUwjoZVPY=</wsse:Password>
<!--<wsu:Created>2013-12-17T13:12:00.429Z</wsu:Created>-->
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">efPSkfHXTM6NFDDD1CJHsw==</wsse:Nonce>
<wsu:Created>2013-12-23T12:17:15Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ord:processOrder>
<!--Optional:-->
<arg0>
<!--Optional:-->
<customerID>234</customerID>
<!--Optional:-->
<itemID>0908923</itemID>
<price>23423</price>
<qty>1000</qty>
</arg0>
</ord:processOrder>
</soapenv:Body>
</soapenv:Envelope>
When i tried to call the service i am getting exception as
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">ns1:MessageExpired</faultcode>
<faultstring>The message has expired</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
Can any one tell me where i am making mistake?
I suspect this is a bug in earlier version of wss4j. If you are parsing the date using SimpleDateFormat, you might want to set the time zone to UTC (Zulu time).
sdf.setTimeZone("UTC");
This however has been fixed in 2.0-beta.
http://grepcode.com/file/repo1.maven.org/maven2/org.apache.wss4j/wss4j-ws-security-dom/2.0-beta/org/apache/wss4j/dom/message/token/UsernameToken.java#226
Edit: This is not a bug in wss4j. The specification states that the time zone must be in UTC.

SharePoint Web Services Team Discussion and Replies

I am trying to get a discussion with all it's replies from the sharepoint web services but only seem to be able to get the root message and not any of the replies. Below is the soap XML. What am I missing?
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.microsoft.com/sharepoint/soap/">
<soapenv:Header/>
<soapenv:Body>
<soap:GetListItems>
<!--Optional:-->
<soap:listName>Team Discussion</soap:listName>
<soap:viewFields>
<ViewFields>
<FieldRef Name='Title'/>
<FieldRef Name='ItemChildCount'/>
<FieldRef Name='Body'/>
</ViewFields>
</soap:viewFields>
<soap:queryOptions>
<QueryOptions>
<Folder>
"http://Lists/Team Discussion/Bite Me"
</Folder>
</QueryOptions>
</soap:queryOptions>
</soap:GetListItems>
</soapenv:Body>
</soapenv:Envelope>
The reply is:
<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>
<GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<GetListItemsResult>
<listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<rs:data ItemCount="2">
<z:row ows_Title="Hello" ows_ItemChildCount="3;#1" ows_Body="<div class="ExternalClass7B4989B3DC264716AD81B9CE55FD38FA"><p>​The text of the message</p></div>" ows_MetaInfo="3;#" ows__ModerationStatus="0" ows__Level="1" ows_ID="3" ows_UniqueId="3;#{6AF6D7DA-0D87-45EC-B002-AA0D153B6286}" ows_owshiddenversion="1" ows_FSObjType="3;#1" ows_Created="2012-01-11 12:21:26" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-01-11 12:21:26" ows_FileRef="3;#Lists/Team Discussion/Hello"/>
<z:row ows_Title="Bite Me" ows_ItemChildCount="1;#1" ows_Body="<div class="ExternalClass76A3DB4368714038B6B75DB0D807240B"><p>​Really?</p></div>" ows_MetaInfo="1;#" ows__ModerationStatus="0" ows__Level="1" ows_ID="1" ows_UniqueId="1;#{336518DC-B806-4DFB-9483-AB8DBB6258B6}" ows_owshiddenversion="1" ows_FSObjType="1;#1" ows_Created="2012-01-09 14:16:29" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-01-09 14:16:29" ows_FileRef="1;#Lists/Team Discussion/Bite Me"/>
</rs:data>
</listitems>
</GetListItemsResult>
</GetListItemsResponse>
</soap:Body>
</soap:Envelope>
EDIT: Each of the above posts should also have a reply.
I eventually found the magic query. It seems sub folders are only returned when you add a query based on date, i.e. this soap request works.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.microsoft.com/sharepoint/soap/">
<soapenv:Header/>
<soapenv:Body>
<soap:GetListItems>
<!--Optional:-->
<soap:listName>969E0130-5727-4E7D-A908-B3A5BC447E24</soap:listName>
<soap:viewFields>
<ViewFields>
<FieldRef Name='Title'/>
<FieldRef Name='Created'/>
<FieldRef Name='Author'/>
<FieldRef Name='Body'/>
</ViewFields>
</soap:viewFields>
<soap:query>
<Query>
<Where>
<Geq>
<FieldRef Name='Created' />
<Value Type='DateTime'>2010-08-20T14:00:00</Value>
</Geq>
</Where>
<OrderBy><FieldRef Name='ThreadIndex' Ascending='true' /></OrderBy>
</Query>
</soap:query>
<soap:queryOptions>
<QueryOptions>
<ViewAttributes Scope="RecursiveAll" IncludeRootFolder="False" />
</QueryOptions>
</soap:queryOptions>
</soap:GetListItems>
</soapenv:Body>
</soapenv:Envelope>
The essential parts are the query element with the date and the query option to specify the query is recursive.
imho shouldn't need the query as it should return everything by default.
The folder option listed in the other article didn't make any difference for me.
Have you checked out this article:
How to access SharePoint's Discussion Board using Web Services
http://geekswithblogs.net/kobush/archive/2007/03/12/108545.aspx