Order XML to soap client - php

I have to make a script that sends a order (XML) to a SOAP client server (this way the supplier can handle the order)
I tried everything but it doesn't work.
Does anybody know what I'm doing wrong?
This is what I have so far:
<?php
$xmlstr = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.datacontract.org/2004/07/Centric.CS.Trade.Standard.WS.SalesOrderService.Contract.Request" xmlns:ns2="http://centric.eu/services/CS/Trade/Standard/WS/">
<SOAP-ENV:Body>
<ns2:LoadSalesOrder>
<ns2:request>
<ns1:SalesOrderRequests>
<ns1:SalesOrderRequest>
<ns1:DeliveryAddress/>
<ns1:DeliveryAddress1>teststraat</ns1:DeliveryAddress1>
<ns1:DeliveryCountry>NL</ns1:DeliveryCountry>
<ns1:DeliveryEmail>test#test.nl</ns1:DeliveryEmail>
<ns1:DeliveryFetchCarrier>true</ns1:DeliveryFetchCarrier>
<ns1:DeliveryFetchDeliveryMode>true</ns1:DeliveryFetchDeliveryMode>
<ns1:DeliveryHouseNo>1</ns1:DeliveryHouseNo>
<ns1:DeliveryMunicipality>ALKMAAR</ns1:DeliveryMunicipality>
<ns1:DeliveryName>Test naam</ns1:DeliveryName>
<ns1:DeliveryPermanent>false</ns1:DeliveryPermanent>
<ns1:DeliveryPhone>06-12345678</ns1:DeliveryPhone>
<ns1:DeliveryPostalCode>1200 RT</ns1:DeliveryPostalCode>
<ns1:Division>AGU_NL</ns1:Division>
<ns1:Key>02</ns1:Key>
<ns1:Language>NL</ns1:Language>
<ns1:Login>7440475</ns1:Login>
<ns1:OrderCustomer>7440475</ns1:OrderCustomer>
<ns1:OrderLines>
<ns1:SalesOrderRequest.OrderLine>
<ns1:Item>113504</ns1:Item>
<ns1:Line>10</ns1:Line>
<ns1:OrderQuantityBU>1.0000</ns1:OrderQuantityBU>
</ns1:SalesOrderRequest.OrderLine>
</ns1:OrderLines>
<ns1:OrderType>100</ns1:OrderType>
<ns1:ReferenceExternal>100000001</ns1:ReferenceExternal>
</ns1:SalesOrderRequest>
</ns1:SalesOrderRequests>
</ns2:request>
</ns2:LoadSalesOrder>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
XML;
$wsdl = 'https://ws.abcb2b.eu/Centric/CS/Trade/cstest/SalesOrderService.svc?wsdl';
$client = new SoapClient($wsdl, array(
'cache_wsdl' => WSDL_CACHE_NONE,
'cache_ttl' => 86400,
'trace' => true,
'exceptions' => true,
));
$xmlVar = new SoapVar($xmlstr, XSD_ANYXML);
$client->LoadSalesOrder($xmlstr);
?>
Fatal error: Uncaught SoapFault exception: [s:Client] The creator of this fault did not specify a Reason. in C:\wamp\soap_request.php:102 Stack trace: #0 C:\wamp\www\soap_request.php(102): SoapClient->__call('LoadSalesOrder', Array) #1 C:\wamp\www\soap_request.php(102): SoapClient->LoadSalesOrder('

Related

Convert PHP SOAP call to Postman

I am trying to make a SOAP call using POSTMAN that will duplicate a call I'm making with a PHP code for testing purposes, but I am getting a "Bad request" error message, so I assume my conversion is incorrect.
The PHP code is:
//Create xml string
$xml=new DomDocument();
$xml->createCDATASection('![CDATA[]]');
$xml->encoding = 'utf-8';
$xml->xmlVersion = '1.0';
$xml->formatOutput = true;
$xsd=$xml->createElement("xsd:schema");
$xml->appendChild($xsd);
$xsdattr=new DOMAttr("xmlns:xsd","http://www.w3.org/2001/XMLSchema");
$xsd->setAttributeNode($xsdattr);
$ZHT=$xml->createElement("ZHT",str_replace(" ","",$username));
$xsd->appendChild($ZHT);
$PASSWORD=$xml->createElement("PASSWORD",str_replace(" ","",$pwd));
$xsd->appendChild($PASSWORD);
$SNL=$xml->createElement("SNL",$date);
$xsd->appendChild($SNL);
$USERNAME=$xml->createElement("USERNAME","");
$xsd->appendChild($USERNAME);
$RETHASIMA=$xml->createElement("RETHASIMA","1");
$xsd->appendChild($RETHASIMA);
$LANG=$xml->createElement("LANG","");
$xsd->appendChild($LANG);
$ROLE=$xml->createElement("ROLE",$role);
$xsd->appendChild($ROLE);
$xmlstring=$xml->saveXML();
//Set SOAP request
$baseURL=$url;
$arrContextOptions=array("ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false,'crypto_method' => STREAM_CRYPTO_METHOD_TLS_CLIENT));
$options = array(
'soap_version' => SOAP_1_1,
'trace' => true,
'exceptions' => true, // disable exceptions
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'encoding' => 'UTF-8',
'cache_wsdl'=>WSDL_CACHE_NONE,
);
$client = new SoapClient($baseURL."?wsdl", $options);
$p=array(
"P_RequestParams" => array (
"RequestID"=>"48",
"InputData"=>$xmlstring
) ,
"Authenticator" => array (
"Password"=>$authpass,
"UserName"=>$authuser
),
);
//SOAP call and response
$response=$client->ProcessRequestJSON($p);
And This is the body I created in POSTMAN:
<?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>
<ProcessRequestJSON xmlns="****">
<P_RequestParams>
<RequestID>48</RequestID>
<InputData>
<?xml version="1.0" encoding="utf-8" ?>
<schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<PARAMS>
<ZHT>****</ZHT>
<PASSWORD>****</PASSWORD>
<SNL>***</SNL>
<USERNAME></USERNAME>
<RETHASIMA>1</RETHASIMA>
<LANG></LANG>
<ROLE>1</ROLE>
</PARAMS>
</schema>
</InputData>
</P_RequestParams>
<Authenticator>
<UserName>****</UserName>
<Password>****</Password>
</Authenticator>
</ProcessRequestJSON>
</soap:Body>
</soap:Envelope>
I'm not sure how to set certain things on POSTMAN.
For example, the following line:
$xsdattr=new DOMAttr("xmlns:xsd","http://www.w3.org/2001/XMLSchema");
How do I set a DOMAttr in POSTMAN?
Or the options?
I set up the headers for XML:
Content-Type: text/xml
SOAPAction: "****/ProcessRequestJSON"
Body: Raw (XML)
I tried putting the inner XML (inside the tag) in "" to indicate a string, but that didn't work either.
The PHP code works correctly, the SOAP call is successful and returns a correct response.
The POSTMAN request returns a "Bad Request" error message.

php soap client with nested childs

I am trying to figure how to create this soap envelope using soap client
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Header>
<m:sendDataExtraccionTraza
xmlns:m="http://www.mop.cl/controlextraccion/xsd/datosExtraccion/SendDataExtraccionRequest">
<m:codigoDeLaObra>OB-0303-204</m:codigoDeLaObra>
<m:timeStampOrigen>2001-12-17T09:30:47Z</m:timeStampOrigen>
</m:sendDataExtraccionTraza>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<m:sendDataExtraccionRequest
xmlns:m="http://www.mop.cl/controlextraccion/xsd/datosExtraccion/SendDataExtraccionRequest">
<m:dataExtraccionSubterranea>
<m:fechaMedicion>17-08-1967</m:fechaMedicion>
<m:horaMedicion>00:01:01</m:horaMedicion>
<m:totalizador>1234567891</m:totalizador>
<m:caudal>12345678.12</m:caudal>
<m:nivelFreaticoDelPozo >12345678.12</m:nivelFreaticoDelPozo >
</m:dataExtraccionSubterranea>
</m:sendDataExtraccionRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Tried making it like this:
$client = new SoapClient($url, array('trace' => 1));
$ns = 'http://www.mop.cl/controlextraccion/xsd/datosExtraccion/SendDataExtraccionRequest';
$headerbody = array('codigoDeLaObra' => POZO_PRUEBA,
'timeStampOrigen' => '2020-01-01T09:30:47Z');
$header = new SOAPHeader($ns, 'sendDataExtraccionTraza', $headerbody);
$client->__setSoapHeaders($header);
$args = array( "fechaMedicion" => "10-10-2020",
"horaMedicion" => "10:01:01",
"totalizador" => "1234567891",
"caudal" => "12345678.12",
"nivelFreaticoDelPozo" => "12345678.12"
);
$res = $client->__soapCall('sendDataExtraccionOp', [
new SoapParam("10-10-2020", "fechaMedicion"),
new SoapParam("10:01:01", "horaMedicion"),
new SoapParam("1234567891", "totalizador"),
new SoapParam("12345678.12", "caudal"),
new SoapParam("1", "nivelFreaticoDelPozo")]);
I am getting an error as result, so i've managed to htmlentities the $client->__getLastRequest() and seeing this outcome
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.mop.cl/controlextraccion/xsd/datosExtraccion/SendDataExtraccionRequest">
<SOAP-ENV:Header>
<ns1:sendDataExtraccionTraza>
<ns1:codigoDeLaObra>OB-0202-251</ns1:codigoDeLaObra>
<ns1:timeStampOrigen>2020-01-01T09:30:47Z</ns1:timeStampOrigen>
</ns1:sendDataExtraccionTraza>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:sendDataExtraccionRequest/>
<horaMedicion>10:01:01</horaMedicion>
<totalizador>1234567891</totalizador>
<caudal>12345678.12</caudal>
<nivelFreaticoDelPozo>1</nivelFreaticoDelPozo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I am missing a <m:dataExtraccionSubterranea> parent inside the senddataExtraccionRequest, and i can't figure how to create it.
Any hint?

php Encoding: Violation of encoding rules

I have a PHP script that is doing a SOAP request to the server. PHP errors out with
SOAP-ERROR: Encoding: Violation of encoding rules
Initial instinct is there is an issue with my request. I took a network capture of the request and sent it to the web server via curl and it seems to have come back OK. The request that is sent by PHP soap and curl is the same which is:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.com/Integrics/Enswitch/API" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:download_music_file><username xsi:type="xsd:string">dovid</username><password xsi:type="xsd:string">passsowrd</password><music xsi:type="xsd:int">45</music><file xsi:type="xsd:int">1</file><checking xsi:type="xsd:int">0</checking></ns1:download_music_file></SOAP-ENV:Body></SOAP-ENV:Envelope>
The response is:
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="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"><soap:Body><download_music_fileResponse xmlns="http://www.example.com/Integrics/Enswitch/API"><gensym><name xsi:type="xsd:string">music_45_1.wav</name><data xsi:type="xsd:base64Binary">BASE 64 REMOVED</data><mimetype xsi:type="xsd:string">audio/x-wav</mimetype></gensym></download_music_fileResponse></soap:Body></soap:Envelope>
The php code that does the quest is:
<?PHP
ini_set("soap.wsdl_cache_enabled", "0");
$uid = 'dovid';
$pass = 'password';
$func = 'download_music_file';
$soap = new SoapClient("enswitch_3.9.wsdl", array('trace' => true, 'exceptions' => false, 'keep_alive' => false, 'connection_timeout' => 15));
$result1 = $soap->$func($uid, $pass, 45, 1,0);
if(isset($soap->__soap_fault)){
echo 'There was an error connecting via SOAP. Below is the error:';
print_r($soap->__soap_fault->faultstring);
}
?>

How to create simple SOAP request?

I tried to create a SOAP request but could not succeed.
SOAP WADL url is http://www.mobipost.com.au/httpapi/Messaging.asmx?WSDL
AND request should be like:
<?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>
<AuthenticationHeader xmlns="http://messaging.mobipostapi.thirdscreen.com.au/">
<UserName>SAMPLE_USER</UserName>
<Password>SAMPLE_PASS</Password>
</AuthenticationHeader>
</soap:Header>
<soap:Body>
<SendSMSToContacts xmlns="http://messaging.mobipostapi.thirdscreen.com.au/">
<oSMS>
<MessageText>THIS IS MESSAGE</MessageText>
</oSMS>
<ContactIDs>
<int>123456789</int>
<int>987654321</int>
</ContactIDs>
</SendSMSToContacts>
</soap:Body>
</soap:Envelope>
I tried:
$url = 'http://www.mobipost.com.au/httpapi/Messaging.asmx?WSDL';
$client = new SoapClient($url);
$result = $client->AuthenticationHeader(array('UserName' => 'SAMPLE_USER','Password' => 'SAMPLE_PASS'));
$result = $client->SendSMSToContacts(array('MessageText' => 'THIS IS MESSAGE'));
$result = $client->ContactIDs(array('123456789', '987654321'));
But it shows Error:
Fatal error: Uncaught SoapFault exception: [Client] Function ("AuthenticationHeader") is not a valid method for this service in D:\xampp\htdocs\globalmobile\send_message_v2.php:26 Stack trace: #0 D:\xampp\htdocs\globalmobile\send_message_v2.php(26): SoapClient->__call('AuthenticationH...', Array) #1 D:\xampp\htdocs\globalmobile\send_message_v2.php(26): SoapClient->AuthenticationHeader(Array) #2 {main} thrown in D:\xampp\htdocs\globalmobile\send_message_v2.php on line 26
Can you please help me to create valid SOAP request to communicate with WSDL server.
Thank you in advance.
There are must be only one request, you send three.
You must create something like this:
1) Set header for authentication:
$auth = $auth = new SOAPAuth('USERNAME', 'PASSWORD');
$header = new SOAPHeader('urn:example.org/auth', 'AuthenticationHeader', $auth);
$client->__setSoapHeaders($header);
2) Create create request with message text and contacts.
$result = $client->SendSMSToContacts(array("MessageText" => "some text", "contactIDs" => array(123456789, 123456789));
P.S. For the debugging create client with:
$client = new SoapClient($url, array('trace' => 1,
'exceptions' => 1,));
and after sending request, look on request that was sended and resopnse on it:
var_dump("REQUEST=", $client->__getLastRequest());
var_dump("RESPONSE=", $client->__getLastResponse());

soap:Envelope SOAP-ENV:Envelope PHP

I'm trying to login to an API using built-in soap functions of PHP. I got a result like this.
[LoginResult]=> false,
[ErrorMsg] => Login failed with the reason : The security object is invalid
This is what required by the API provider.
<?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://tempuri.org/Example/Service1">
<objSecurity>
<WebProviderLoginId>test</WebProviderLoginId>
<WebProviderPassword>test</WebProviderPassword>
<IsAgent>false</IsAgent>
</objSecurity>
<OutPut />
<ErrorMsg />
</Login>
</soap:Body>
</soap:Envelope>
&, here is what I was able to produce using functions.
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/Example/Service1">
<SOAP-ENV:Body>
<ns1:Login>
<objSecurity>
<WebProviderLoginId>test</WebProviderLoginId>
<WebProviderPassword>test</WebProviderPassword>
<IsAgent>false</IsAgent>
</objSecurity>
<OutPut/>
<ErrorMsg/>
</ns1:Login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Here is the code I used to send the request.
<?php
class objSecurity {
function objSecurity($s, $i, $f) {
$this->WebProviderLoginId = $s;
$this->WebProviderPassword = $i;
$this->IsAgent = $f;
}
}
class nextObject {
function nextObject($objSecurity) {
$this->objSecurity=$pobjSecurity;
$this->OutPut=NULL;
$this->ErrorMsg=NULL;
}
}
$url = 'http://example.com/sampleapi/test.asmx?WSDL';
$client = new SoapClient($url, array("soap_version" => SOAP_1_1,"trace" => 1));
$struct = new objSecurity('test', 'test', false);
$data = new nextObject($struct);
$soapstruct2 = new SoapVar($data, SOAP_ENC_OBJECT);
print_r(
$client->__soapCall(
"Login",
array(new SoapParam($soapstruct2, "inputStruct"))
)
);
echo $client->__getLastRequest();
?>
These are the differences I found.
In my request xmlns:xsi is missing.
Requirement starts with <soap:Envelope, But my request starts with <SOAP-ENV:Envelope.
There is an extra xmlns:ns1 in my request.
& The function name tag starts with ns1:.
Please help me to make my request into the required format.
I don't know much about the SOAP and I'm using PHP version 5.3.13 with CakePHP 2.3.0. Sorry, for my bad English.
Here is the solution. :)
<?php
$url = 'http://example.com/sampleapi/test.asmx?WSDL';
$client = new SoapClient($url, array("soap_version" => SOAP_1_1,"trace" => 1));
$user_param = array (
'WebProviderLoginId' => "test",
'WebProviderPassword' => "test",
'IsAgent' => false
);
$service_param = array (
'objSecurity' => $user_param,
"OutPut" => NULL,
"ErrorMsg" => NULL
);
print_r(
$client->__soapCall(
"Login",
array($service_param)
)
);
echo $client->__getLastRequest();
?>
& the request was:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/Example/Service1">
<SOAP-ENV:Body>
<ns1:Login>
<ns1:objSecurity>
<ns1:WebProviderLoginId>test</ns1:WebProviderLoginId>
<ns1:WebProviderPassword>test</ns1:WebProviderPassword>
<ns1:IsAgent>false</ns1:IsAgent>
</ns1:objSecurity>
</ns1:Login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Thanks to this link.
PHP SOAP Request not right

Categories