PHP Soap And .Net Dataset - php

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!

Related

How can I identify available SOAP functions?

I am new to SOAP and trying to make my first request to https://nts.elwis.de/server/MessageServer.php?wsdl
I already made up a post call sending it to the SOAP endpoint at "https://nts.elwis.de/server/MessageServer.php". But it returns "Procedure 'get_messages_query' not present".
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:nts="http://www.ris.eu/nts/3.0">
<soapenv:Header/>
<soapenv:Body>
<nts:get_messages_query>
</nts:get_messages_query>
</soapenv:Body>
</soapenv:Envelope>
If I read the specs in the link above, I cannot find any problem why the SOAP service could not find my function.
Do you have any ideas?
Best
Karsti
Use this simple script, written in PHP, which gives you enough information. Function and type lists will help you to make correct SOAP call. I'm not familiar with this SOAP service, so you need to pass correct values for parameters.
<?php
// SOAP
$soap = new SoapClient("https://nts.elwis.de/server/MessageServer.php?wsdl");
// List functions
echo 'Functions: '.'</br>';
$functions = $soap->__getFunctions();
foreach($functions as $item) {
echo $item.'</br>';
}
echo '</br>';
// List types
echo 'Types: '.'</br>';
$types = $soap->__getTypes();
foreach($types as $item) {
echo $item.'</br>';
}
echo '</br>';
// Consume SOAP
$params = array(
'message_type' => '',
'ids' => '',
'validity_period' => array (
'date_start' => date("Y-m-d"),
'date_end' => date("Y-m-d")
),
'dates_issue' => array (
'date_start' => date("Y-m-d"),
'date_end' => date("Y-m-d")
),
'paging_request' => array(
'offset' => 0,
'limit' => 0,
'total_count' => true
)
);
$responce = $soap->get_messages($params);
var_export($responce);
?>
In case somebody needs a working request for the endpoint https://nts.elwis.de/server/MessageServer.php
Here is an example:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.ris.eu/nts.ms/1.0.3.0">
<SOAP-ENV:Body>
<ns1:get_messages_query>
<ns1:message_type>WRM</ns1:message_type>
<ns1:paging_request>
<ns1:offset>0</ns1:offset>
<ns1:limit>10</ns1:limit>
<ns1:total_count>true</ns1:total_count>
</ns1:paging_request>
</ns1:get_messages_query>
</SOAP-ENV:Body>

Soap PHP WSDL XML formatting

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.

SOAPClient won't attach parameters on method call

I'm working to connect via web services to another company using PHP. The connection is successful based on the response from the web service. There is not user validation or password in the process.
The validation of the method is successful too based on the result of print_r($client->__getFunctions()) and print_r($client->__getTypes()) where I can see the information on both cases.
The problems come when the parameters are passing to the method, the request don't have the parameters in the XML body :
<?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:GetToken/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I did different kinds of call with the same result:
$response = $client->__soapCall('GetToken', array('parameters' => $params));
or
$response = $client->GetToken(array('parameters' => $params));
or
$response = $client->__soapCall('GetToken', array($params));
or
$response = $client->GetToken(array($params));
Every try is the same response from the web service because the method is not attaching the parameters to the request
[GetTokenResult] => stdClass Object
(
[Token] =>
[Url] =>
[StatusCode] => 400
[StatusDescription] => Value cannot be null.
)
This is my code:
Try{
$wsdlLocation = 'http://webservice.com/Agent.svc?wsdl';
$client = new SoapClient($wsdlLocation,array('location' => $wsdlLocation,
'trace' => true,
'exceptions' => true
)
);
$params = array(
'Key' => '123456',
'ReturnUrl' => 'http://Anyweb.com',
'Name' => 'John Doe',
'Office' => 'NorhWest',
'Business' => 'PL',
'Email' => 'my#email.com',
);
$response = $client->__soapCall('GetToken', array('parameters' => $params));
print_r($response);
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
}
catch (SoapFault $fault) {
trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
}
Also, I tested the web service using the XMLspy. Sending a request from this tool with the same values and parameters. The response in this case was successful. So the issue is not the service on the other company.
Any idea how I can resolve this issue. Thanks.
Well, after some time I found the answer of this. The soap service was waiting for an array named 'request' instead of 'parameter'. This fix all the issue.
$response = $client->__soapCall('GetToken', array('request' => $params));
I hope this save time to another people.

php soapclient Array to string conversion

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.

SOAP Client returning 'Wrong Version' Error

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.

Categories