Using PHP SOAP client on .NET web service - php

I am trying to consume a .NET SOAP service but I'm currently just getting a 'false' response.
Visiting the service endpoint tells me the following:
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.
<?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>
<SendData xmlns="http://tempuri.org/">
<myObj>string</myObj>
</SendData>
</soap:Body>
</soap:Envelope>
But when I check my request, it is sending the following:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body>
<ns1:SendData>
<ns1:myObj>My data</ns1:myObj>
</ns1:SendData>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
So we can see that my request has different nodes titles and also adds in "ns1:" to the parameters.
Here is my (brief) PHP
$soap = new SoapClient('wsdl.xml', array("trace" => 1, "exception" => 1));
$call = $soap->__soapCall("SendData", array("SendData" => array("myObj" => "My data")));
So my question is: Could this difference in request schema be responsible for the request failing or is this just another way of writing the same thing? If it is responsible, is it possible to write my request exactly as specified at the endpoint?

It is the same thing.
In the given example <SendData xmlns="http://tempuri.org/"> is without namespace prefix (the ns1 in your own request) so default prefix is used, and it specifies it with xmlns attribute for itself and its descendants.
In your request ns1 namespace prefix is defined using xmlns:ns1="http://tempuri.org/" and used in <ns1:SendData>.

Related

PHP soapClient xml soap envelope format error

I call a method with php soapClient class, like this:
$client->ResetAppPassword($request);
and my envelope is send like this
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://xmlns.xxxx.com/PATH/TO/V1/schema"
xmlns:ns2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<SOAP-ENV:Body>
<ns1:ResetAppPasswordRequest>
<ns1:username>TEST</ns1:username>
<ns1:app>TEST</ns1:app>
</ns1:ResetAppPasswordRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But the server response:
The message must be an instance of: {http://www.w3.org/2003/05/soap-envelope}Envelope
and this is because the service is specting other format:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:sch="http://xmlns.xxxx.com/PATH/TO/V1/schema">
<soap:Body>
<sch:ResetAppPasswordRequest>
<sch:username>TEST</sch:username>
<sch:app>DMS</sch:app>
</sch:ResetAppPasswordRequest>
</soap:Body>
</soap:Envelope>
So the i already tried to send it via php-CURL but with this solution I need to parse the XML response, so this make the process really hard, because I want to manage the response as an object.
Can someone help me... PLEASSSE..

How to make proper SOAP request using PHP SoapClient when we see an example

I want to receive data using method GetCruise
How to do that in php using SoapClient, of course i know all URLs and I've got PartnerName, Password and AgencyCode
especially i need to know how to construct proper header of envelope using SoapClient::__setSoapHeaders
GetCruise
Call:
Proxy.Availability.GetCruise(“FO11060119”);
Parameters:
CruiseCode - the cruise code to be returned
Returns:
a fully described cruise (including itinerary and segments of an itinerary).
Example of soap envelope:
(headers must contain agency data - name paswword etc. i've got it)
SOAPAction: "http://schemas.costacrociere.com/WebAffiliation/GetCruise"
<?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:Header>
<Agency xmlns="http://schemas.costacrociere.com/WebAffiliation">
<Code>1111</Code>
<Culture />
</Agency>
<Partner xmlns="http://schemas.costacrociere.com/WebAffiliation">
<Name>AAAA</Name>
<Password>XXXX</Password>
</Partner></soap:Header>
<soap:Body>
<GetCruise xmlns="http://schemas.costacrociere.com/WebAffiliation">
<CruiseCode>FO11060119</CruiseCode>
</GetCruise>
</soap:Body>
</soap:Envelope>

Are these 2 soap headers the same?

I've been told that my soap header must be like this :
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ws="http://ws.dgpys.deloitte.com">
<soap:Header>
<axis2:ServiceGroupId xmlns:axis2="http://ws.apache.org/namespaces/axis2">
urn:uuid:FA7EB13C84D91BC34B1373986557015
</axis2:ServiceGroupId>
</soap:Header>
<soap:Body>
...
</soap:Body>
My soap header is :
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://ws.dgpys.deloitte.com\">
<SOAP-ENV:Header>
<ns1:ServiceGroupId>
urn:uuid:FA7EB13C84D91BC34B1373986557015
</ns1:ServiceGroupId>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
...
</SOAP-ENV:Body>
Mine doesn't work. I searched for a solution but I couldn't find anything. How can I fix this? Or which topics should I learn?
No, your http://schemas.xmlsoap.org/soap/envelope/ is SOAP 1.1 and requested is http://www.w3.org/2003/05/soap-envelope/, the SOAP 1.2 namespace.
Don't get confused by the soap/SOAP-ENV or axis/ns1, they are just namespace prefixes.
Also your first message seems to be missing the declaration of the axis2 namespace prefix, but I suppose xmlns:ws="http://ws.dgpys.deloitte.com" is meant to read xmlns:axis2="http://ws.dgpys.deloitte.com".
If the provider asks you to send SOAP 1.2, then use a SOAP 1.2 namespace and message format. This is why relevant code should be present in your question, but you need to instantiate your SoapClient like this:
$client = new SoapClient("some.wsdl", array('soap_version' => SOAP_1_2));

soap api with betfair

It's my first time using the SOAP API by BetFair I have created one XML file and one file that will call that file. I am not understanding how can I call this and get an output. I have created the XML file below:
<?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>
<login xmlns="http://www.betfair.com/publicapi/v3/BFGlobalService/">
<request>
<locationId xmlns="">0</locationId>
<username xmlns="">usrname</username>
<password xmlns="">password</password>
<productId xmlns="">18</productId>
<vendorSoftwareId xmlns="">0</vendorSoftwareId>
</request>
</login>
</soap:Body>
</soap:Envelope>
Now to call this file I have also created one php file to do this.
BetFair has given this link for the login api: https://api.betfair.com/global/v3/BFGlobalService.wsdl
<?php
$get_data = file_get_contents("http://pixelonsell.com/dev2/betfair/login.xml");
$b = html_entity_decode($get_data);
$data= urlencode($b);
print_r($data);
$client = new SoapClient("https://api.betfair.com/global/v3/BFGlobalService.wsdl");
$result = $client->LoginReq($data);
print_r($result);
?>
I don't know why it's not working; can you help me out with this? Thank you in advance.
I would avoid using a dedicated SOAP library; in my experience they often don't work because of inconsistencies in the ways different servers implement the SOAP specification. Use a simple HTTP/HTTPS library instead, with the following headers
SOAPAction: urn:login
Content-Length: #{myContentLength}
Content-Type: text/xml
User-Agent: #{myUserAgent}
and the following payload (assuming you're using the Free API):
<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<m:login xmlns:m="https://api.betfair.com/global/v3/BFGlobalService">
<m:request>
<username>#{myUsername}</username>
<password>#{myPassword}</password>
<locationId>0</locationId>
<vendorSoftwareId>0</vendorSoftwareId>
<productId>82</productId>
</m:request>
</m:login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
It looks to me like you're using the wrong namespace for the login element; should be 'https://api.betfair.com/..' not 'http://www.betfair.com/..'.
Good luck.

Adding optional parameters in SOAP call in PHP

The format of my SOAP call needs to be:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body>
<ns1:FunctionName>
<ns1:HostUserName>hostuser</ns1:HostUserName>
<ns1:HostPassword>pass</ns1:HostPassword>
<ns1:OwnerName>owner</ns1:OwnerName>
<ns1:UserName>user</ns1:UserName>
<ns1:OptionalParam>
<ns1:Parameters>
<ns1:Parameter Name="FirstName">First<ns1:/Parameter>
<ns1:Parameter Name="LastName">Last<ns1:/Parameter>
<ns1:/Parameters>
</ns1:OptionalParam>
<ns1:/FunctionName>
</SOAP-ENV:Body>
How do I represent this in a PHP request?
I build the request like this:
$client = new SoapClient($url,array('trace' => 1));
$data['HostUserName']=$this->hostname;
$data['HostPassword']=$this->hostpassword;
$data['OwnerName']=$this->ownername;
$data['UserName']=$username;
$data['FirstName']=$FirstName;
$data['LastName']=$LastName;
$result = $client->FunctionName($data);
I've tried a few combinations of building arrays, SOAPVAR and SOAPPARAM but nothing has worked.
The target SOAP server is .NET based.
Any suggestions?
Thanks

Categories