How do I send an array in SOAP? - php

I have a PHP file, which sends SOAP request
$client = new SoapClient('http://xyz');
$client->call('example', array('param1'=>'value2')
I want to do this same request using SoapUI:
<soapenv:Envelope [..]>
<soapenv:Header/>
<soapenv:Body>
<urn:call soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<param1 xsi:type="xsd:string">example</param1>
<param2 xsi:type="xsd:anyType">
??
</param2>
</urn:call>
</soapenv:Body>
</soapenv:Envelope>
How do I encode the above example in XML?

it should be something like that:
<soapenv:Envelope [..]>
<soapenv:Header/>
<soapenv:Body>
<urn:call soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<param1 xsi:type="xsd:string">example</param1>
<param2 xsi:type="xsd:anyType">
<param1 xsi:type="xsd:string">value2</param1>
</param2>
</urn:call>
</soapenv:Body>
</soapenv:Envelope>

Use json_encode() and then send the array as a string representation.

In this case there is a nice PHP SOAP client function: $client->__getLastRequest()
It showed that, the request is built like this:
<param2 xsi:type="ns2:Map">
<item xsi:type="ns2:Map">
<key xsi:type="xsd:string">param1</key>
<value xsi:type="xsd:string">param2</value>
</item>
</param2>

Related

Can't send a soap request -Invalid API namespace-

I'm trying to send a soap request with simple curl call in a laravel application but i get the next error.
<faultcode>soap:Client</faultcode>
<faultstring>Invalid API namespace</faultstring>
This is the XML request
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Security SOAP-ENV:mustUnderstand="1">
<wsse:UsernameToken>
<wsse:Username>usename</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">randompass</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<soapenv:Body>
<requestMessage
xmlns="urn:schemas-cybersource-com:transaction-data-N.NN">
<merchantID>themerchantid</merchantID>
<merchantReferenceCode>the reference</merchantReferenceCode>
<billTo>
<firstName>Name</firstName>
<lastName></lastName>
<street1></street1>
<city></city>
<state></state>
<postalCode></postalCode>
<country></country>
<email>name#mail.com</email>
</billTo>
<item id="1">
<unitPrice>25</unitPrice>
<quantity>1</quantity>
</item>
<purchaseTotals>
<currency>EUR</currency>
</purchaseTotals>
<card>
<accountNumber>9898989898989898</accountNumber>
<expirationMonth>10</expirationMonth>
<expirationYear>20</expirationYear>
</card>
<ccAuthService run="true"/>
</requestMessage>
</soapenv:Body>
</soapenv:Envelope>
I don't know why I'am getting this error. What's wrong with the request?
Your namespace that is currently
xmlns="urn:schemas-cybersource-com:transaction-data-N.NN"
should be
xmlns="urn:schemas-cybersource-com:transaction-data-1.155"
You will also need to populate the billTo fields since they are usually required.

Soap error: "looks like we got no XML document"

I check the difference bettwen a call who work simulating soap with curl request which work here is the xml that work:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.test.com/">
<soapenv:Header/>
<soapenv:Body>
<ser:DoItdoItRequest1>
<version>1.0</version>
</ser:DoItdoItRequest1>
</soapenv:Body>
</soapenv:Envelope>
I change my code using SoapClient to be more clean than emulating a curl request, but my server return me:
looks like we got no XML document
When debugging I get from client->__getLastRequest()
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://service.test.com/">
<SOAP-ENV:Body>
<ns1:DoItdoItRequest1>
<version>1.0</version>
</ns1:DoItdoItRequest1>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The only difference seems to be:
<ser:DoItdoItRequest1>
against
<ns1:DoItdoItRequest1>
Do you know how to change this ns1: to a ser: with SoapClient ? an option maybe ?
I can't find helpful help about that...
Regards.

How to receive soap request from codeigniter controller?

How I can receive a soap request in my controller? For your convenient I am sharing the sample soap format. From this I need to get "message" field. Can you please suggest me any solution.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<ns1:NotifySOAPHeader xmlns:ns1="http://www.huawei.com.cn/schema/common/v2_1">
<ns1:timeStamp>111029084631570</ns1:timeStamp> <ns1:traceUniqueID>100001200101110623021721000011</ns1:traceUniqueID>
</ns1:NotifySOAPHeader>
</soapenv:Header>
<soapenv:Body>
<ns2:notifySmsReception xmlns:ns2="http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local">
<ns2:correlator>00001</ns2:correlator>
<ns2:message>
<message>Hello world</message>
<dateTime>2010-08-09T00:00:00.000+08:00</dateTime>
</ns2:message>
</ns2:notifySmsReception>
</soapenv:Body>
</soapenv:Envelope>

SOAP Service: I have a sample request file XML but getting confused about the format

I'm working on integrating to a remote service running Apache Axis. I have been given a sample request file that looks like the following
<?xml version="1.0" encoding="UTF-8"?>
<request xmlns="http://api.somedomain.com/openSession" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="openSession.xsd">
<session key="xabc123092"/>
<user name="admin" password="secret"/>
</request>
I know SOAP requires "envelope and body" such that the request conforms with
<?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>
....
</soapenv:Body>
</soapenv:Envelope>
Now I'm confused about the sample request file given to me. I have tried to craft the following SOAP request with some SOAPAction in the request header but to no avail
<?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>
<soapenv:openSession>
<session key="xabc123092"/>
<user name="admin" password="secret"/>
</soapenv:openSession>
</soapenv:Body>
</soapenv:Envelope>
The above gives the following
<?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>
<soapenv:Fault>
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>org.xml.sax.SAXException: operation description is missing parameter description!</faultstring>
<detail>
<ns1:hostname
xmlns:ns1="http://xml.apache.org/axis/">api.somedomain.com
</ns1:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
Can someone tell me what I'm missing here?
Not sure if you are still facing this problem. It was missing request element along with the namespace in the soap request. Please try below:
<?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>
<request xmlns="http://api.somedomain.com/openSession" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="openSession.xsd">
<session key="xabc123092"/>
<user name="admin" password="secret"/>
</request>
</soapenv:Body>
</soapenv:Envelope>

Soap header without header name php

I'm having a problem in order to create a soap call. As one can see the header that is being supplied from a 3rd party client doesn't have a header name. I need to create a soap call by passing the username and password to the soap request which doesn't have a name in the header. I have tried several examples but no success. The call below works in soap UI but I'm having serious problems when it comes to php. Any help would be much appreciated
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://namespace.example.com/">
<soapenv:Header>
<int:password>123</int:password>
<int:login>abc</int:login>
</soapenv:Header>
<soapenv:Body>
<int:getEventTree>
<!--Optional:-->
<lang>en</lang>
</int:getEventTree>
</soapenv:Body>
</soapenv:Envelope>
Please take a look at http://php.net/manual/en/soapclient.dorequest.php
You can use code like:
$response = $soapClient->__doRequest(
$request,
$endpoint,
$soapAction,
$soapVersion,
$one_way
);
$request could be defined as a string containing xml, such as:
$request =
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/""xmlns:int="http://namespace.example.com/">
<soapenv:Header>
<int:password>123</int:password>
<int:login>abc</int:login>
</soapenv:Header>
<soapenv:Body>
<int:getEventTree>
<!--Optional:-->
<lang>en</lang>
</int:getEventTree>
</soapenv:Body>
</soapenv:Envelope>';
You can define the rest of the arguments in the __doRequest() call depending on your configuration.

Categories