wash_out(0.9.0) has been very helpful for me in implementing a SOAP service in my Rails(3.1) app. One little problem I am facing is that for XML payload in the SOAP body, < > are getting replaced by
< >
Here's my code snippet
render :soap => "<person><firstname>larry</firstname></person>"
Output is
<?xml version="1.0" encoding="UTF-8"?>
<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" xmlns:tns="http://www.w3.org/2001/12/soap-envelope">
<soap:Body>
<tns:index_response>
<value xsi:type="xsd:string"><person><firstname>larry</firstname></person></value>
</tns:index_response>
</soap:Body>
</soap:Envelope>
Is this a bug or can I fix this by some configuration or additional code.
Kindly help.
Try this (didn't test it):
render :soap => "<person><firstname>larry</firstname></person>".html_safe
I was able to resolve this. There was 1 thing I was doing wrong.
I am using savon client to call my SOAP service. I was doing
client = Savon::Client.new(wsdl: "")
result = client.call(...)
puts result
This was displaying < and >
The right way to access the response content in my case is
result.body[:index_response][:value]
result.body returns a hash
With Nokogiri I could do doc = Nokogiri::XML(result.body.to_xml)
This works well with XML in payload.
Related
I'm trying to send a SOAP request to the Loqate services following their API documentation found here.
The documentation says the SOAP end point is
https://api.addressy.com/Capture/Interactive/Find/v1.1/wsdlnew.ws
and the sample request is:
<?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>
<Find
xmlns="http://api.addressy.com/">
<Key>AA11-AA11-AA11-AA11</Key>
<Text>wr5 3da</Text>
<IsMiddleware>True</IsMiddleware>
<Container>GB|RM|ENG|3DA-WR5</Container>
<Origin>52.182,-2.222</Origin>
<Countries>GB,US,CA</Countries>
<Limit>10</Limit>
<Language />
<Bias />
<Filters />
<GeoFence />
</Find>
</soap:Body>
</soap:Envelope>
So I load up Postman and make these steps, following the Postman guide from their blog.
When I send the request, I just get back this page . I'm not sure why it's not working.
How can I make a SOAP request to this API? What am I missing?
That's not the service endpoint, it's an address where you can get the WSDL. Inside that WSDL you will find the service endpoint:
<soap:address location="http://services.postcodeanywhere.co.uk/Capture/Interactive/Find/v1.10/soapnew.ws"/>
Send your request there. The endpoint is over http, but the https seems to be working on the same address: https://services.postcodeanywhere.co.uk/Capture/Interactive/Find/v1.10/soapnew.ws
One other thing. If you want a more specific client than Postman, you could try SoapUI.
I am trying to insert data into the SQL server database through SOAP XML Web service from IOS using Swift code, but it is get only Id value which is auto generate in database ,but i cant insert my data into table because it will get null values which i have passed in Soap message.
My Code in swift
<?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>
<CreateUserDetail xmlns='http://tempuri.org/'>
<userdetail>
<UserDetail>
<Id>1</Id>
<Username xsi:type='xs:string'>username</Username>
<Password xsi:type='xs:string'>password</Password>
</UserDetail>
</userdetail>
</CreateUserDetail>
</soap:Body>
</soap:Envelope>
I have surfing many of blog and sites and finally I got solution for it here is a soap message with solution
my new soap message is written below
<SOAP-ENV:Envelope xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:tns='http://tempuri.org/' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<tns:CreateUserDetail>
<tns:userdetail>
<tns:Id xmlns:tns='http://schemas.datacontract.org/2004/07/WcfService1'>1</tns:Id>
<tns:Username xmlns:tns='http://schemas.datacontract.org/2004/07/WcfService1'>String</tns:Username>
<tns:Password xmlns:tns='http://schemas.datacontract.org/2004/07/WcfService1'>String</tns:Password>
</tns:userdetail>
</tns:CreateUserDetail>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
you have to just replace xmlns:tns='your target namespace' which i have write in id,username,password element
hope it will help someone
I'm getting a soap request like this:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<notifications xmlns="xxxxx">
<sometags></sometags>
<Notification>
<Id>yyyyy</Id>
<sObject xsi:type="sf:Dog" xmlns:sf="urn:some.enterprise.object.soap.com">
<sf:Id>zzzzz</sf:Id>
</sObject>
</Notification>
</notifications>
</soapenv:Body>
</soapenv:Envelope>
and I want to find out what kind of object is the notification about (== I want to read the sObject's type attribute, so
that I know whos type of sObject is related the id tag).
I want to be able to do something similar:
if (sObject.type.equals("Dog"))
//do something
if (sObject.type.equals("Cat"))
//do something else
but how can i get that attribute value in the soap request?
I'm using java with cxf libraries .
Thank you,
Cloutz
Just use Interceptor & do what ever you want.
I have used XmlSlurper successfully before, but am struggling to parse the following XML - it is a response from a call to the Pingdom API. I have tried following the namespace declaration examples, but I just get an error message on the ns1 and ns2 values. Can anybody help point me in the right direction? The xml looks like this:-
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="urn:methods"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns2="urn:PingdomAPI"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:Auth_loginResponse>
<return xsi:type="ns2:Auth_LoginResponse">
<status xsi:type="xsd:int">0</status>
<sessionId xsi:type="xsd:string">mysessionId</sessionId>
</return>
</ns1:Auth_loginResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
after using the XmlSlurper it just concatenates the 0 and mysessionId to one string
0mysessionId
Try this, giving your xml is stored in the xml variable :
def records = new XmlSlurper().parseText(xml).declareNamespace(
'SOAP-ENV':'http://schemas.xmlsoap.org/soap/envelope/',
ns1:'urn:methods',
xsd:'http://www.w3.org/2001/XMLSchema',
xsi:'http://www.w3.org/2001/XMLSchema-instance',
ns2:'urn:PingdomAPI'
)
println records.'SOAP-ENV:Body'.'ns1:Auth_loginResponse'.return.status
println records.'SOAP-ENV:Body'.'ns1:Auth_loginResponse'.return.sessionId
I want to make a request to a SOAP Web Service but I don't want to install any gems.
Is there any way to just make the request using plain XML?
I think it's trivial but there might be something I've missed, because all implementations/tutorials were using a gem.
I think that the SOAP response, can be handled also as a XML response right?
The request is this:
POST /services/tickets/issuer.asmx HTTP/1.1
Host: demo.demo.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>
<Tick xmlns="http://demo.com/test/test">
<Request>
<Username>string</Username>
<Password>string</Password>
<AcquirerId>int</AcquirerId>
<RequestType>string</RequestType>
<ExpirePreauth>unsignedByte</ExpirePreauth>
<BitPerSec>int</BitPerSec>
<Office>string</Office>
</Request>
</Tick>
</soap12:Body>
</soap12:Envelope>
You could do this:
def post_xml(path, xml)
host = "http://demo.demo.com"
http = Net::HTTP.new(host)
resp = http.post(path, xml, { 'Content-Type' => 'application/soap+xml; charset=utf-8' })
return resp.body
end
The XML response would be returned by this method.