Unable to call .NET ASMX from PHP - php

I have the following - currently hosted - SOAP service that was created in .NET that I'm trying to call from PHP:
POST /ExampleService/ExampleService.asmx HTTP/1.1
Host: dev.examplesite.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://localhost:51713/ExampleService.asmx/RegisterPerson"
<?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:Header>
<UserCredentials xmlns="http://localhost:51713/ExampleService.asmx">
<UserID>string</UserID>
<AuthKey>string</AuthKey>
</UserCredentials>
</soap:Header>
<soap:Body>
<RegisterPerson xmlns="http://localhost:51713/ExampleService.asmx">
<requestItem>
<RequestResult>string</RequestResult>
<Firstname>string</Firstname>
<Lastname>string</Lastname>
</requestItem>
</RegisterPerson>
</soap:Body>
</soap:Envelope>
and I'm trying to call it using the following PHP code:
<?php
$ns = "http://dev.examplesite.com/ExampleService/ExampleService.asmx";
$wsdl_url = "http://dev.examplesite.com/ExampleService/ExampleService.asmx?wsdl";
$client = new SOAPClient($wsdl_url);
$header = new SoapHeader(
$ns,
'UserCredentials',
array(
'UserID' => "1",
'AuthKey' => "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
)
);
$client->__setSoapHeaders($header);
$params = array(
'Firstname' => 'John',
'Lastname' => 'Doe'
);
$client->__soapCall('RegisterPerson',$params);
?>
This however results in the following error:
Fatal error: Uncaught SoapFault exception: [soap:MustUnderstand] Missing required header 'UserCredentials'. in /home/devops1/public_html/asmxtest/register.php:43 Stack trace: #0 /home/devops1/public_html/asmxtest/register.php(43): SoapClient->__soapCall('RegisterPerso...', Array) #1 {main} thrown in /home/devops1/public_html/asmxtest/register.php on line 43
I've tried a few other methods but all met with no success. One thing that concerns me is the fact that we are reaching across over the wire to this web service which is already hosted on a testing server, and the localhost:51713 is ringing alarm bells. Should this be changed to a fully qualified domain name such as dev.examplesite.com?

For as easy as the SoapClient is supposed to be, I've never had success w/ it. In just about every case we have rolled our own process, which always seemed to work better.
Example:
// set our headers to pass in cURL
$headers = array(
'Content-type: text/xml;charset="utf-8"',
'Accept: text/xml',
'Cache-Control: no-cache',
'Pragma: no-cache',
'SOAPAction: ' . $action,
'Content-length: '.strlen($soap)
);
// initiate cURL
try {
$_ch = curl_init();
curl_setopt($_ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($_ch, CURLOPT_URL, WEB_SERVICE_URL);
curl_setopt($_ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($_ch, USERPWD, USER_ID . ":" . PASSWORD);
curl_setopt($_ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($_ch, CURLOPT_TIMEOUT, 10);
curl_setopt($_ch, CURLOPT_POST, true);
curl_setopt($_ch, CURLOPT_POSTFIELDS, $soap);
curl_setopt($_ch, CURLOPT_HTTPHEADER, $headers);
// process the request and get the result back
$response = curl_exec($_ch);
curl_close($_ch);
return $response;
} catch (Exception $e) {
capDebug(__FILE__, __LINE__, "Error calling the web service: " . $e->getMessage(), "/tmp/errors.log");
return false;
}
We've had to massage the data afterwards, but it always works!

Related

Correct XML request with Curl: getting blank XML response

I was trying to hit XML request from PHP SOAP Client according to the following provided SOAP API documentation.
WSDL Schema
Refer to the following URL.
http://[SERVER_IP]/PowerSuite/PSXMLSearch.asmx?wsdl
4 Input/Output
4.1 Search Supplier Code and Name (PSXMLSearchSupplier)
Input : PSXML_SEARCH_SUPP
Output : PSXML_SEARCH_SUPP_Response
6 Field definition
6.1 PSXML_SEARCH_SUPP - The main entry point and the authentication information.
MSGID
USERID
PASSWORD
OPTION
SUPPNO
But when i run with SOAP client it gives me a following error
Object reference not set to an instance of an object
So after long research on internet, i decided to send XML request via CURL, i have created following Schema for XML request and send it via CURL request
$soapUrl = "https://[MY_SERVER_DOMAIN]/PowerSuite/PSXMLSearch.asmx"; // asmx URL of WSDL
// xml post structure
$xml_post_string = '<?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>
<PSXML_SEARCH_SUPP xmlns="https://[MY_SERVER_DOMAIN]/PowerSuite/PSXMLSearch.asmx">
<MSGID>TRAVEK_E1</MSGID>
<USERID>GCOT</USERID>
<PASSWORD>CKHOSKIS6</PASSWORD>
<OPTION>LIKE</OPTION>
<SUPPNO>RK0048</SUPPNO>
</PSXML_SEARCH_SUPP>
</soap:Body>
</soap:Envelope>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"https://[MY_SERVER_DOMAIN]/PowerSuite\"",
"Content-length: ".strlen($xml_post_string),
);
$url = $soapUrl;
// PHP cURL for https connection with auth
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "GCONNECT:Connect#786");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// converting
$response = curl_exec($ch);
curl_close($ch);
// converting
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
// convertingc to XML
$parser = simplexml_load_string($response2);
// user $parser to get your data out of XML response and to display it.
echo "<pre>";
print_r($parser);
echo "</pre>";
die();
But even after that i only get empty XML response as can see below
SimpleXMLElement Object
(
)
Please guide am i sending a correct XML schema, or their needs to be some thing amend into it?
I checked with RapidAPI, it shows the correct response, i have shown the request in the image below:
In FORM
https://gcdnb.pbrd.co/images/a9NdABt6rXQl.png
In XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xh="http://www.xmlhk.com/">
<soapenv:Header/>
<soapenv:Body>
<xh:PSXMLSearchSupplier>
<!--Optional:-->
<xh:PSXML_SEARCH_SUPP>
<!--Optional:-->
<xh:MSGID>TRAVEK_EBOOK001</xh:MSGID>
<!--Optional:-->
<xh:USERID>ABCUSER</xh:USERID>
<!--Optional:-->
<xh:PASSWORD>Connect#786</xh:PASSWORD>
<!--Optional:-->
<xh:OPTION>LIKE</xh:OPTION>
<!--Optional:-->
<xh:SUPPNO>ABDECS</xh:SUPPNO>
<!--Optional:-->
<xh:SUPPNAME>?</xh:SUPPNAME>
</xh:PSXML_SEARCH_SUPP>
</xh:PSXMLSearchSupplier>
</soapenv:Body>
</soapenv:Envelope>
I tried the same above with CURL request and got that working, i found that,following to be changed in my previous CURL request
, which on the raw tab in ReadyAPI
"SOAPAction: \"http://www.xmlhk.com/PSXMLSearchSupplier\"",
To work this with SOAP Client i just need to used multi dimensional array with $params['PSXML_SEARCH_SUPP'] shows below
$wsdl = "https://ps.gerrys.com.pk/PowerSuite/PSXMLSearch.asmx?WSDL";
$params['PSXML_SEARCH_SUPP'] = array(
'MSGID' => "TRAVEK_EBOOK001",
'USERID' => "GCONNECT",
'PASSWORD' => "Connect#786",
'OPTION' => 'LIKE',
'SUPPNO' => 'RK0048'
);
try {
$soap = new SoapClient($wsdl);
$data = $soap->PSXMLSearchSupplier($params);
echo "<pre>";
print_r($data);
echo "</pre>";
die();
}
catch(Exception $e) {
$e->getMessage();
var_dump($e->getMessage());
die();
}

PHP | SOAP 1.2 | How to set WS Addressing

Here is the WSDL ...
I am using the SOAP Client in PHP with documentation HERE ...
Soap Call
$wsdl = 'https://api.krollcorp.com/EBusinessTest/Kroll.Dealer.EBusiness.svc/Docs?singleWsdl';
try {
$client = new SoapClient($wsdl, array('soap_version' => SOAP_1_2, 'trace' => 1));
// $result = $client->SubmitPurchaseOrder();
$result = $client->__soapCall("SubmitPurchaseOrder", array());
} catch (SoapFault $e) {
printf("\nERROR: %s\n", $e->getMessage());
}
$requestHeaders = $client->__getLastRequestHeaders();
$request = $client->__getLastRequest();
$responseHeaders = $client->__getLastResponseHeaders();
printf("\nRequest Headers -----\n");
print_r($requestHeaders);
printf("\nRequest -----\n");
print_r($request);
printf("\nResponse Headers -----\n");
print_r($responseHeaders);
printf("\nEND\n");
Output
ERROR: The SOAP action specified on the message, '', does not match the HTTP SOAP Action, 'http://tempuri.org/IEBusinessService/SubmitPurchaseOrder'.
Request Headers -----
POST /EBusinessTest/Kroll.Dealer.EBusiness.svc HTTP/1.1
Host: api.krollcorp.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.6.19
Content-Type: application/soap+xml; charset=utf-8; action="http://tempuri.org/IEBusinessService/SubmitPurchaseOrder"
Content-Length: 200
Request -----
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://tempuri.org/"><env:Body><ns1:SubmitPurchaseOrder/></env:Body></env:Envelope>
Response Headers -----
HTTP/1.1 500 Internal Server Error
Content-Length: 637
Content-Type: application/soap+xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 06 Sep 2017 12:42:57 GMT
END
Attempts
I am a beginner at using SOAP APIs.
I believe this is failing because SOAP 1.2 uses WsHttpBinding instead of BasicHttpBinding.
I am not sure how to set WS Addressing with the SOAP Client in PHP ...
Below code is working for me.You can enable Ws-A Addressing and call soap method-
$client = new SoapClient("http://www.xyz.Services?Wsdl", array('soap_version' => SOAP_1_2,'trace' => 1,'exceptions'=> false
));
$wsa_namespace = 'http://www.w3.org/2005/08/addressing';
$ACTION_ISSUE = 'http://www.xyx/getPassword';// Url With method name
$NS_ADDR = 'http://www.w3.org/2005/08/addressing';
$action = new SoapHeader($NS_ADDR, 'Action', $ACTION_ISSUE, true);
$to = new SoapHeader($NS_ADDR, 'To', 'http://www.xyx.svc/Basic', false);
$headerbody = array('Action' => $action,'To' => $to);
$client->__setSoapHeaders($headerbody);
//$fcs = $client->__getFunctions();
//pre($client->__getLastRequest());
//pre($fcs);
$parameters=array('UserId'=>'12345678','MemberId'=>'123456','Password' => '123456','PassKey' => 'abcdef1234');
;
$result = $client->__soapCall('getPassword', array($parameters));//getPassword method name
print_r(htmlspecialchars($client->__getLastRequest()));// view your request in xml code
print_r($client->__getLastRequest());die; //Get Last Request
print_r($result);die; //print response
Dude, I totally feel your pain. I was able to get this to work but I don't think this is the right way, but it is pointing in the right direction. A caveat though, you have to know what namespace soap_client is going to assign to the addressing. Best way is just to capture the request XML and look for what namespace is attache to the addressing, and then pass it in. Below is my code with a default of 'ns2' for namespace, but you can't count on it for your example. Good Luck!
private function generateWSAddressingHeader($action,$to,$replyto,$message_id=false,$ns='ns2')
{
$message_id = ($message_id) ? $message_id : $this->_uniqueId(true);
$soap_header = <<<SOAP
<{$ns}:Action env:mustUnderstand="0">{$action}</{$ns}:Action>
<{$ns}:MessageID>urn:uuid:{$message_id}</{$ns}:MessageID>
<{$ns}:ReplyTo>
<{$ns}:Address>{$replyto}</{$ns}:Address>
</{$ns}:ReplyTo>
<{$ns}:To env:mustUnderstand="0">$to</{$ns}:To>
SOAP;
return new \SoapHeader('http://www.w3.org/2005/08/addressing','Addressing',new \SoapVar($soap_header, XSD_ANYXML),true);
}
My solution is
Send request using SoapUi
Copy request http log from SoapUi screen ( Bottom of SoapUi program)
Past that code into the PHP project as fallows
$soap_request = '{copy that part from SoapUi http log}';
$WSDL = "**wsdl adres**";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, $WSDL);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array(
'Content-Type: application/soap+xml; charset=utf-8',
'SOAPAction: "run"',
'Accept: text/xml',
'Cache-Control: no-cache',
'Pragma: no-cache',
'Content-length: '. strlen($soap_request),
'User-Agent: PHP-SOAP/7.0.10',
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, $soap_request);
$response = curl_exec($ch);
if (empty($response)) {
throw new SoapFault('CURL error: '.curl_error($ch), curl_errno($ch));
}
curl_close($ch);

Invoking API with SOAP using SoapClient - can't find method

I'm trying to connect to an API that uses SOAP. It is working for me with php/curl, but what I'd really like to do is use SoapClient, which looks like it would produce much cleaner code.
This is the php that works:
$xml_post_string = '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope
/" xmlns:v300="http://V300">
<soapenv:Header/>
<soapenv:Body>
<v300:GetNote soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<Request xsi:type="get:Request" xmlns:get="http://getNote.note.V300">
<Security xsi:type="req:Security" xmlns:req="http://request.base.V300">
<Password xsi:type="xsd:string">'.$soapPassword.'</Password>
<Username xsi:type="xsd:string">'.$soapUser.'</Username>
</Security>
<NoteID xsi:type="xsd:string">'.$soapNoteID.'</NoteID>
</Request>
</v300:GetNote>
</soapenv:Body>
</soapenv:Envelope>';
$headers = array(
"Content-type: application/soap+xml;charset=utf-8",
"Accept: text/xml",
"SOAPAction: https://webservices.aus.vin65.com/V300/NoteService.cfc?wsdl",
"Content-length: ".strlen($xml_post_string),
);
$url = $soapUrl;
$ch = curl_init();
echo("set curl\n");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_VERBOSE,false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
echo("about to execute\n");
// converting
$response = curl_exec($ch);
echo('Got '.strlen($response)." characters in response\n");
curl_close($ch);
echo("Response:\n".$response."\n");
And this is my attempt at a SoapClient version, informed by this helpful StackExchange user over here: How to make a PHP SOAP call using the SoapClient class
class Security{
function Security($Username,$Password){
$this->Username = $Username;
$this->Password=$Password;
}
}
class Request{
function Request($Security,$NoteID){
$this->Security = $Security;
$this->NoteID = $NoteID;
}
}
$client = new SoapClient($soapUrl);
$security = new Security($soapUser,$soapPassword);
$securityArray = array("Username"=>$soapUser,"Password"=>$soapPassword);
//$request = new Request($security,$soapNoteID);//gave error message "expects parameter 2 to be array"
//$request = array("Security"=>$security,"NoteID"=>$soapNoteID);//gave error message "No such operation 'GetNote'"
$request = array("Security"=>$securityArray,"NoteID"=>$soapNoteID);//gave error message "No such operation 'GetNote'"
echo("Showing Request:\n");
var_dump($request);
$response=null;
try{
$response = $client->__soapCall("GetNote",$request);
}catch(Exception $ex){
echo("Caught Exception: ".$ex->getMessage()."\n");
echo("Last Request was: ".$client->__getLastRequest()."\n");
echo("Last Request Headers: ".$client->__getLastRequestHeaders()."\n");
echo("Last Response was: ".$client->__getLastResponse()."\n");
echo("Last Response Headers: ".$client->__getLastResponseHeaders()."\n");
}
if($response){
var_dump($response);
}
As you can see, I've tried a couple of different ways to feed it the user/password/NoteID information, noting down which error message it gives me each time. Currently it's claiming that there's 'no such operation GetNote' - definintely not right, but I don't know what the underlying problem is.
Thanks in advance for any pointers.
When i do $client->__getFunctions(), the method GetNote method shows up and works
<?php
$client = new SoapClient('https://webservices.aus.vin65.com/V300/NoteService.cfc?wsdl');
/**
print_r($client->__getFunctions());
Array
(
[0] => Response SearchNotes(Request $Request)
[1] => Response AddUpdateNote(Request $Request)
[2] => Response GetNote(Request $Request)
)
*/
$result = $client->GetNote([
'Security' => [
'Password' => 'XXX',
'Username' => 'XXX'
],
'NoteID' => 'XXX'
]);
print_r($result);

Call SOAP client using NuSoap PHP with Document/literal wrapped

Im trying to make a SOAP call, but have to many problems.
Im using this:
$client = new nusoap_client('http://odigo.xxx.com/xxx/servlet/services/WebCallBack?wsdl');
$client -> setEndpoint('https://odigo2.xxx.com/xxx/servlet/services/WebCallBack.WebCallBackHttpSoap11Endpoint/');
$client->soap_defencoding = 'UTF-8';
error message:
$error = $client->getError();
if ($error) {
die("client construction error: {$error}\n");
}
$param = array('skillKeyWord' => 'yyy',
'phoneNumber' => '999999999',
'user' => 'XXX',
'password' => 'XXX',
);
$result = $client->call('saveCallBack', array('parameters' => $param), '', '', false, true);
The IT department of the Client tell me, the request are wrong, because: "need to use Document/literal wrapped, not encoded" and "parameters are wrong encapsulated"
The correct call they send to us, is this example:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<saveCallBack xmlns ="http://odigo.xxx.com/2009/09/21/webcallback.xsd" xmlns:ns2="http://webcallback.ws.bean.model.odigo.xxx.com/xsd" xmlns:ns3="http://administration.bean.model.odigo.xxx.com/xsd">
<webCallBack>
<ns2:date>0</ns2:date>
<ns2:phoneNumber>9999999</ns2:phoneNumber>
<ns2:skillKeyWord>yyy</ns2:skillKeyWord>
</webCallBack>
<user>
<ns3:login>XXX</ns3:login>
<ns3:password>XXX</ns3:password>
</user>
</saveCallBack>
</soap:Body>
</soap:Envelope>
I dont know how i can send this format call using nusoap, or using this XML to make a call using nusoap.
Any help its appreciated.
Try using CURL. Code is shown below:
$soap_body = '<?xml version="1.0" encoding="utf-8"?>'.
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'.
'<soap:Body>'.
'<saveCallBack xmlns ="http://odigo.xxx.com/2009/09/21/webcallback.xsd" xmlns:ns2="http://webcallback.ws.bean.model.odigo.xxx.com/xsd" xmlns:ns3="http://administration.bean.model.odigo.xxx.com/xsd">'.
'<webCallBack>'.
'<ns2:date>0</ns2:date>'.
'<ns2:phoneNumber>9999999</ns2:phoneNumber>'.
'<ns2:skillKeyWord>yyy</ns2:skillKeyWord>'.
'</webCallBack>'.
'<user>'.
'<ns3:login>XXX</ns3:login>'.
'<ns3:password>XXX</ns3:password>'.
'</user>'.
'</saveCallBack>'.
'</soap:Body>'.
'</soap:Envelope>';
$headers = array
(
'Content-Type: text/xml; charset="utf-8"',
'Content-Length: '. strlen($soap_body),
'Accept: text/xml',
'Cache-Control: no-cache',
'Pragma: no-cache'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://odigo.xxx.com/xxx/servlet/services/WebCallBack?wsdl');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $soap_body);
$result = curl_exec($ch);
//do something useful with $result variable

PHP & XML - How to generate a soap request in PHP from this XML?

I am completly new to SOAP operations.
I have been provided with an XML document (SOAP) to get some collection points for a shipping method.
From the manual located here:
http://privpakservices.schenker.nu/package/package_1.3/packageservices.asmx?op=SearchCollectionPoint
I can see that I need to use the following SOAP request:
POST /package/package_1.3/packageservices.asmx HTTP/1.1
Host: privpakservices.schenker.nu
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://privpakservices.schenker.nu/SearchCollectionPoint"
<?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>
<SearchCollectionPoint xmlns="http://privpakservices.schenker.nu/">
<customerID>long</customerID>
<key>string</key>
<serviceID>string</serviceID>
<paramID>int</paramID>
<address>string</address>
<postcode>string</postcode>
<city>string</city>
<maxhits>int</maxhits>
</SearchCollectionPoint>
</soap:Body>
</soap:Envelope>
The thing is that i don't know how to send this as a request using PHP, and how to get the response.
Any help to pinpoint me in the right direction, is much appreciated.
UPDATE
I can read the response data with var_dump. However, I am not able to read individual element data.
I need to read data as below
foreach($parser as $row) {
echo $row->customerID;
echo $row->key;
echo $row->serviceID;
}
If anyone should be interested, i have provided the correct answer:
$soapUrl = "http://privpakservices.schenker.nu/package/package_1.3/packageservices.asmx?op=SearchCollectionPoint";
$xml_post_string = '<?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><SearchCollectionPoint xmlns="http://privpakservices.schenker.nu/"><customerID>XXX</customerID><key>XXXXXX-XXXXXX</key><serviceID></serviceID><paramID>0</paramID><address>RiksvÅ gen 5</address><postcode>59018</postcode><city>Mantorp</city><maxhits>10</maxhits></SearchCollectionPoint></soap12:Body></soap12:Envelope>';
$headers = array(
"POST /package/package_1.3/packageservices.asmx HTTP/1.1",
"Host: privpakservices.schenker.nu",
"Content-Type: application/soap+xml; charset=utf-8",
"Content-Length: ".strlen($xml_post_string)
);
$url = $soapUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
$parser = simplexml_load_string($response2);
following example might help you.
SOAP XML schema
<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.dataaccess.com/webservicesserver/">
<x:Header/>
<x:Body>
<web:NumberToDollars>
<web:dNum>10</web:dNum>
</web:NumberToDollars>
</x:Body>
</x:Envelope>
PHP code
$wsdl = 'http://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL';
try{
$clinet=new SoapClient($wsdl);
$ver =array("dNum"=>"2002");
$quates=$clinet->NumberToDollars($ver);
var_dump($quates);
}
catch(SoapFault $e)
{
echo $e->getMessage();
}

Categories