So I am using Soap client in PHP and I'm trying to make a request on some WSDL. I try to have a specific output but it seems a bit far from what I try to do. Maybe I don't do this right. I'm a bit new to WSDL.
Here is the result I want:
<SOAP-ENV:Body>
<loc:sendSms>
<loc:addresses>9000000000</loc:addresses>
<loc:senderName>9000000</loc:senderName>
<loc:message>test SMS</loc:message>
</loc:sendSms>
</SOAP-ENV:Body>
This is what I try to fit my requirement, but it ends with a server error:
$MCIResp = (array) $_soapClient->__soapCall('sendSms',
'sendMessage' => array(
'addresses' => '9000000000',
'senderName' => '9000000',
'message' => 'test SMS '
)
);
And this is the error I get from this request:
"SoapFault exception: [Client] SOAP-ERROR: Encoding: object has no
'sendmessage' property";
EDIT: Made some improvements on that by getting inspiration on some posts
Here is my code now:
$_soapClient = new SoapClient(
null,
array(
'location' => 'http://someIP/parlayxsmsgw/services/SendSmsService?wsdl',
'uri' => 'http://someIP/parlayxsmsgw/services/SendSmsService?wsdl',
'trace' => 1,
'cache_wsdl' => WSDL_CACHE_NONE,
'use' => SOAP_LITERAL,
'style' => SOAP_DOCUMENT,
'stream_context' => stream_context_create(array(
'http' => array(
'header' => 'servicekey: someservicekey'
),
)),
)
);
$params = new \SoapVar("<sendSms><addresses>90000000000</addresses><senderName>90000000</senderName><message>test SMS</message></sendSms>",XSD_ANYXML);
And then I do a
$_soapClient->whatEverNameHereWillBeIgnored($params);
This is now the XML I generate:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<sendSms>
<addresses>989127184955</addresses>
<senderName>98307066</senderName>
<message>test SMS</message>
</sendSms>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But I receive this as a response:
Unexpected subelement sendSms
do the "loc:" are mandatory to solve this ? Because when I add it in the raw xml it says that
Undeclared namespace prefix "loc"
Thanks,
I strongly advise you to use a WSDL to PHP generator such as PackageGenerator, it will ease you the request construction so you won't have to wonder how to construct the request, it will be cristal clear.
Related
Trying to use PHP-s own SoapClient, but I have come across an obstacle.
I'm using __soapCall for making requests, but the query fails, because encodingStyle attribute is set:
$client = new SoapClient(NULL, array(
'location' => 'http://myUri.com',
'uri' => 'http://namespace.com/producer'
));
$result = $client->__soapCall('GET_ALL');
Now doing $client->__getLastRequest(); shows Envolope node like this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
How to remove SOAP-ENV:encodingStyle attribute and still use __soapCall(); ?
Apperantly I was missing "use" parameter in SoapClient construct. Solution:
$client = new SoapClient(NULL, array(
'location' => 'http://myUri.com',
'uri' => 'http://namespace.com/producer',
'use' => SOAP_LITERAL,
));
I got an issue here. I am trying make a request to a Web Appi: http://www.speedex.gr/getvoutrans/getvoutrans.asmx?WSDL
And I am sending a request to insertPodData();
I am using PHP and SOAP.
I am succesfull at connecting and giving the correct credentials. However I am not able to send a Dataset (cause I do not know the right way), so i get an empty dataset.
Datasets are for .NET lang. So it is kind of tricky with the php.
I tried already to send it as an array, i still get an empty result.
Here are some coding.
PHP:
$dataset = array(
'schema' => array(
'Enter_Branch_Id' => $speedex_branch_id,
'SND_Customer_Id' => $speedex_cust_id,
'SND_Agreement_Id' => $speedex_appi_key,
'RCV_Name' => 'Test',
'RCV_Addre1' => 'Test Adress',
'RCV_Zip_Code' => '54636',
'RCV_City' => 'Thessaloniki',
'RCV_Country' => 'Greece',
'RCV_Tel1' => '*******',
'Voucher_Weight' => '0',
),
'any' => ''
);
try {
$soap = new SoapClient("http://www.speedex.gr/getvoutrans/getvoutrans.asmx?WSDL",array('trace' => true));
$oAuthResult = $soap->insertPodData(
array(
'username' => $speedex_usrn,
'password' => $speedex_psw,
'VoucherTable' => $dataset,
'_tableFlag' => 3
)
);
$resultVoucher = $oAuthResult;
print_r($resultVoucher);
echo '<br>';
echo "REQUEST:\n" . htmlentities($soap->__getLastRequest()) . "\n";
die();
}catch(SoapFault $fault) {
die('<h1>Ooooops something is broken. Refresh or contact module creator </h1><br>'.$fault);
}
This is returning this result
RESULT: stdClass Object ( [insertPodDataResult] => 1 [newVoucherTable] => stdClass Object ( [schema] => [any] => ) )
REQUEST:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:insertPodData>
<ns1:username>****</ns1:username>
<ns1:password>****</ns1:password>
<ns1:VoucherTable>********************TestTest Adress54636ThessalonikiGreece********</ns1:VoucherTable>
<ns1:_tableFlag>3</ns1:_tableFlag>
</ns1:insertPodData>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
As you can observe the Dataset is not created and all the values are passed with out a reference.
Any ideas clues? Thanks in advance!
I have an array a couple of levels deep in my SOAP request like below. When I run my SoapRequest I get Notice (8): Array to string conversion and my XML response does not convert the Array in RTrans to XML and I have no idea why. How I am creating the SOAP request and the XML version of it can be found below.
The Request:
$r['request'] = array(
'request' => array(
'user' => 'test',
'password' => 'test',
'RTrans' => array(
'Transactions' => array(
'Criteria' => array(
'Name' => 'Thomas'
)
)
)
)
);
try{
$response = $this->apiClient->DoQuery($r);
}
catch(Exception $e){
debug($e);
}
The XML Version
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://webServices/">
<SOAP-ENV:Body>
<ns1:DoNormalEnquiry>
<request>
<username>test</usernmae>
<password>test</password>
<RTrans>Array</RTrans>
</request>
</ns1:DoNormalEnquiry>
</SOAP-ENV:Body>
I think RTrans is defined as a String. Please have a look at the wsdl file.
Maybe thats the reason you got "Array" in the xml.
To send an array to your soapservice you could convert it to json.
json_encode( array('Transactions' => array('Criteria' => array('Name' => 'Thomas')));
or define a complex datatype.
Maybe SoapVar will help you.
Hi guys I am trying to do a SOAP request with php, unfortunately it always returns the Error 'Wrong Version'.
My request looks like this:
<?php
$option=array('trace'=> true, 'cache_wsdl' => WSDL_CACHE_NONE, 'soap_version' => SOAP_1_2, 'exeptions' => true,);
$soapClient=new SoapClient('http://www.SOMEURL.net/SOAPAPI/HEX_XMLIF_1_1_0-0?wsdl',$option);
$soapClient->__setLocation('http://www.SOMEURL.net/SOAPAPI/HEX_XMLIF_1_1_0-0');
try{
$parameters = array(
'Version' => '1.1.0',
'TransactionIdentifier' => 'X4711',
'TimeStamp' => '2013-10-24T16:56:10',
'Target' => 'Test',
'POS' => array (
'Source' => array(
'RequestorID' => array(
'ID' => '709900001',
'ID_Context' => '1234',
'ID_Operator' => 'BJT',
'ID_Token' => '135975505',
'ID_Key' => 'znt'),
'ISOCurrency' => 'EUR',
'ISOCountry' => 'DE'),
),
'CarPark' => array(
'Code' => 'FRA8')
);
$soapClient->CarParkInformation($parameters);
}catch(SoapFault $fault){
echo '<br/><br/> Error Message : <br/>',
$fault->getMessage();
echo '<br/><br/>';
echo 'Request : <br/><xmp>',
$soapClient->__getLastRequest();
echo '</xmp><br/> Response : <br/><xmp>',
$soapClient->__getLastResponse();}
?>
According to the documentation which came with the WSDL file, my request is just fine. The only thing I am missing is a header. The header in the documentation is empty ("")-> No idea how to add an empty header to the request.
I don't think that is the reason for the version error...?
The request which is created looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="de.znt.hexapi">
<SOAP-ENV:Body>
<ns1:GetCarParkInformationRQ>
<ns1:Version>1.1.0</ns1:Version>
<ns1:TransactionIdentifier>X4711</ns1:TransactionIdentifier>
<ns1:TimeStamp>2013-10-24T16:56:10</ns1:TimeStamp>
<ns1:Target>Test</ns1:Target>
<ns1:POS>
<ns1:Source>
<ns1:RequestorID>
<ns1:ID>709900001</ns1:ID>
<ns1:ID_Context>1234</ns1:ID_Context>
<ns1:ID_Operator>BJT</ns1:ID_Operator>
<ns1:ID_Token>135975505</ns1:ID_Token>
<ns1:ID_Key>znt</ns1:ID_Key>
</ns1:RequestorID>
<ns1:ISOCurrency>EUR</ns1:ISOCurrency>
<ns1:ISOCountry>DE</ns1:ISOCountry>
</ns1:Source>
</ns1:POS>
<ns1:CarPark>
<ns1:Code>FRA8</ns1:Code>
</ns1:CarPark>
</ns1:GetCarParkInformationRQ>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I have no idea why I am getting "Wrong Version" error, I tried with 1.1 and 1.2 and I have been testing around for a few days.
Does anyone have a clue what to do?
Problem FIXED - I have been using the wrong endpoint.
I try to make a request to a .NET WSDL function called GetPeriodicValues. The function requires some params and the problem is that SoapClient creates an incorrect XML.
This PHP-code...
$client = new SoapClient(self::URL , array('trace' => 1, 'encoding' => 'UTF-8', 'soap_version' => SOAP_1_1));
$params = array('name' => 'myname', 'address' => 'myaddress');
$result = $client->__soapCall('GetPeriodicValues', array('parameters' => $params), array());
...genereates the following request-XML (I have excluded some irrelevant content):
<SOAP-ENV:Body>
<ns1:RequestOf_GetPeriodicValuesParameters/>
</SOAP-ENV:Body>
But I would expect it to create this
<SOAP-ENV:Body>
<ns1:RequestOf_GetPeriodicValuesParameters>
<ns1:name>myname</ns1:name>
<ns1:address>myaddress</ns1:address>
</ns1:RequestOf_GetPeriodicValuesParameters>
</SOAP-ENV:Body>
How should i include the params in the function-call?
Problem solved. What I learned was that the XML-output is dependent on the WSDL and in my case it wanted me to put params in an array with the key "Params". However, looking at the XML return by the WSDL I found no such information, instead it looked like the key "parameters" should be used. I'm not sure, but perhaps something was wrong with the service.