PHP SOAPCall Input is null - php

I'm getting the following error:
Fatal error: Uncaught SoapFault exception: [s:Client] Service
operation Pickup_Cancel failed due to validation errors: Input is null
Here's my code:
$client = new SoapClient("https://etrack.postaplus.net/APIService/PostaWebClient.svc?singleWsdl", array("trace" => 1, "exception" => 0));
$params = array(
"CodeStation" => `BEY`,
"PickupNumber" => `1`,
"Reason" => `test reason`,
"Password" => `sss`,
"ShipperAccount" => `acc`,
"UserName" => `acc`,
);
$client->Pickup_Cancel($params);

The awnser to the question you didn't ask is probably: replace the backticks (`) by singlequotes (')
-- Edit. That was not the problem.
Here is the case. SOAP can be a pain to get going. My experience is to use a good soap class or just non-wsdl mode. Read up on this in the docs: https://www.php.net/manual/en/soapclient.soapcall.php
So don't do this:
$return = $soapClient->functionName($data);
But this:
$return = $soapClient->__SoapCall('functionName', $data);
Also get a grip on what the server wants, load the WSDL url into a client like SoapUI https://www.soapui.org/ (its free). This lets you check if the SoapServer works and how you should approach it with your call.
In your case the WSDL states this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:pos="http://schemas.datacontract.org/2004/07/PostaWebClient">
<soapenv:Header/>
<soapenv:Body>
<tem:Pickup_Cancel>
<!--Optional:-->
<tem:CLIENTINFO>
<!--Optional:-->
<pos:CodeStation>asd</pos:CodeStation>
<!--Optional:-->
<pos:Password>asd</pos:Password>
<!--Optional:-->
<pos:ShipperAccount>asd</pos:ShipperAccount>
<!--Optional:-->
<pos:UserName>asd</pos:UserName>
</tem:CLIENTINFO>
<!--Optional:-->
<tem:PickupNumber>asd</tem:PickupNumber>
<!--Optional:-->
<tem:Reason>asd</tem:Reason>
</tem:Pickup_Cancel>
</soapenv:Body>
</soapenv:Envelope>
Which translates to this PHP code:
$client = new SoapClient("https://etrack.postaplus.net/APIService/PostaWebClient.svc?singleWsdl");
$params = [
'Pickup_Cancel' => [
'CLIENTINFO' => [
'Password' => 'sss',
'ShipperAccount' => 'acc',
'UserName' => 'acc',
'CodeStation' => '',
],
'PickupNumber' => '',
'Reason' => '',
],
];
$client->__SoapCall("Pickup_Cancel", $params);
See how the array matches the WSDL xml format?
This should also give you the feedback you need to proceed. If not, its probably time to get 'real' help :) Goodluck.

Related

Multidimensional Array with PHP Soap Client

I'm trying to create a SOAP Client, but I need to send a multi-dimensional array (I think) as requested in the documentation, example below:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.senior.com.br">
<soapenv:Body>
<ser:ColaboradoresAdmitidos>
<user>String</user>
<password>String</password>
<encryption>Integer</encryption>
<parameters>
<NumEmp>Integer</NumEmp>
<AbrTipCol>String</AbrTipCol>
<IniPer>DateTime</IniPer>
<FimPer>DateTime</FimPer>
</parameters>
</ser:ColaboradoresAdmitidos>
</soapenv:Body>
</soapenv:Envelope>
I create a array like this:
$arguments = [
'user' => 'xxxxx',
'password' => 'xxxxxxxxxx',
'encryption' => 0,
'parameters' => array(
'NumEmp' => 1,
'AbrTipCol' => '1',
'IniPer' => '01/01/2019',
'FimPer' => null
),
];
$client = new SoapClient($url, array('trace' => 1));
dd($arguments, $client->__soapCall("colaboradoresAdmitidos", $arguments), $client->__getLastRequest());
However in the request, it seems that it does not accept the array, in fact I did some tests, and in addition to the first 3 parameters, but none enter the generated XML.
I already made the array in different ways, and changed the parameter value, but it always returns as below:
<?xml version="1.0" encoding="UTF-8"?>\n
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://services.senior.com.br">
<SOAP-ENV:Body>
<ns1:ColaboradoresAdmitidos>
<user>xxxxxxx</user>
<password>xxxxxxxxx</password>
<encryption>0</encryption>
<parameters/>
</ns1:ColaboradoresAdmitidos>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Someone could help me, because the server understands that the parameter is missing, so I can't execute the query.
Searching the internet, I discovered a lot of people with this problem and who couldn't solve it. I discovered the error.
This happens when the parameters do not match those registered in the WSDL. in my case: the documentation mentions the parameters with a capital letter, however, I had to use it with a small letter.
It seems that the parameter key has to be the same value as the one registered in wsdl.
ex:
$arguments = [
'user' => 'xxxxx',
'password' => 'xxxxxxxxxx',
'encryption' => 0,
'parameters' => array(
'numEmp' => 1,
'abrTipCol' => '1',
'iniPer' => '01/01/2019',
'fimPer' => null
)];

Create an php array for sent to SOAP service

I have hml which works fine in SOAPUI:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"
xmlns:wssc="http://schemas.datacontract.org/2004/07/WSSC.V4.DMS.EKV.WssDocsService">
<soapenv:Header/>
<soapenv:Body>
<tem:CreateDocument>
<!--Optional:-->
<tem:parameters>
<!--Optional:-->
<!--Optional:-->
<wssc:DocType>01</wssc:DocType>
<!--Optional:-->
<!--Optional:-->
<!--Optional:-->
<wssc:FieldValues>
<wssc:BaseDocumentField xsi:type="wssc:DocumentField"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--Optional:-->
<wssc:Name>value1</wssc:Name>
<!--Optional:-->
<wssc:Value>email#email.email</wssc:Value>
</wssc:BaseDocumentField>
<wssc:BaseDocumentField xsi:type="wssc:DocumentField"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--Optional:-->
<wssc:Name>content</wssc:Name>
<!--Optional:-->
<wssc:Value>just text</wssc:Value>
</wssc:BaseDocumentField>
<wssc:BaseDocumentField xsi:type="wssc:DocumentField"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--Optional:-->
<wssc:Name>name</wssc:Name>
<!--Optional:-->
<wssc:Value>number</wssc:Value>
</wssc:BaseDocumentField>
</wssc:FieldValues>
<wssc:UserMail>email#email.email</wssc:UserMail>
</tem:parameters>
</tem:CreateDocument>
</soapenv:Body>
</soapenv:Envelope>
I need to create an array to repeat its structure.
Now I have such an array, but it does not work to the full:
<?php
$params = array(
'parameters' => array(
'DocType' => '01',
'UserMail' => 'email#email.email',
'FieldValues' => array(
'BaseDocumentField' => array(
'name' => 'something',
'value' => 'something',
),
'BaseDocumentField' => array(
'name' => 'something',
'value' => 'something',
),
),
)
);
$client = new SoapClient("http://servicename?wsdl", array("trace" => 1, "exceptions" => 0, "login" => $login, "password" => $password));
$result = $client->CreateDocument($params);
try {
$request = $client->CreateDocument($params);
$last_request = $client->__getLastRequest();
} catch (SoapFault $exception) {
$last_request = $client->__getLastRequest();
}
var_dump($last_request);
?>
The function __getLastRequest produces the following result:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://schemas.datacontract.org/2004/07/WSSC.V4.DMS.EKV.WssDocsService"
xmlns:ns2="http://tempuri.org/">
<SOAP-ENV:Body>
<ns2:CreateDocument>
<ns2:parameters>
<ns1:DocType>01</ns1:DocType>
<ns1:FieldValues>
<ns1:BaseDocumentField/>
</ns1:FieldValues>
<ns1:UserMail>email#email.email</ns1:UserMail>
</ns2:parameters>
</ns2:CreateDocument>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I do not understand how to properly construct an array so that the section is displayed correctly.
how can I do it?
If you're working with a complex WSDL, you should definitively use a WSDL to php generator such as the PackageGenerator project. It'll generate all the classes required to construct the request then to receive the response. Using a good IDE such as Eclipse or PhpStorm, you'll have the full auto-completion wich will ease you the request construction without having to wonder how to do it.

PHP, SOAPClient: Cannot find dispatch method

This is my WSDL XML: (Generated with SoapUI)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://soap.test.com/">
<soapenv:Header/>
<soapenv:Body>
<ser:myMethod>
<user>
<id>?</id>
<name>?</name>
</user>
<code>?</code>
</ser:myMethod>
</soapenv:Body>
</soapenv:Envelope>
And my PHP code to consume the "myMethod" method:
$opts = array(
'location' => 'http://example.com/myServices?WSDL',
'uri' => 'http://soap.test.com'
);
$client = new SOAPClient(null, $opts);
$res = $client->__soapCall('myMethod', array(
"id" => "123",
"name" => "Sam"
));
var_dump($res);
And I get the Cannot find dispatch method for {http://soap.test.com} myMethod error.
I've tested the SOAP with SoupUI and it has responsed correctly.
What is wrong here?

Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client] Operation '' is not defined in the WSDL for this service

I have a wsdl http://soap.m4u.com.au/?wsdl
Need to call "sendMessages" method but I am getting following error every time.
Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client] Operation '' is not defined in the WSDL for this service
My client file code is :
$client = new SoapClient("http://soap.m4u.com.au/?wsdl", array("trace" => 1, "soap_version" => SOAP_1_2));
$params = array(
"authentication" => array(
"userId" => "******",
"password" => "********"
),
"requestBody" => array(
"messages" => array(
"message" => array(
"sequenceNumber"=>"1",
"recipients" => array(
"recipient" => array(
"999966663333"
)
),
"content" => "Message Content"
)
)
)
);
$response = $client->__soapCall("sendMessages", array($params));
Update
This web-service using SOAP 1.1 not SOAP 1.2, when I changed I got following error:
Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client] The request is either not well-formed or is not valid against the relevant schema.
$client = new SoapClient("http://soap.m4u.com.au/?wsdl", array("trace" => 1, "soap_version" => SOAP_1_1));
Replcae this line,
Correction: "soap_version"=>SOAP_1_1
This service is using SOAP 1.1 not SOAP 1.2
Edited:
Now problem is in your request message structure. That content field is under messages. BTW, your final soap request should be like this,
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://xml.m4u.com.au/2009">
<soapenv:Header/>
<soapenv:Body>
<ns:sendMessages>
<ns:authentication>
<ns:userId>?</ns:userId>
<ns:password>?</ns:password>
</ns:authentication>
<ns:requestBody>
<ns:messages sendMode="normal">
<!--1 or more repetitions:-->
<ns:message format="SMS" sequenceNumber="0">
<!--You may enter the following 7 items in any order-->
<!--Optional:-->
<ns:origin>?</ns:origin>
<ns:recipients>
<!--1 or more repetitions:-->
<ns:recipient uid="0">?</ns:recipient>
</ns:recipients>
<ns:content>?</ns:content>
<!--Optional:-->
<ns:scheduled>?</ns:scheduled>
<!--Optional:-->
<ns:deliveryReport>false</ns:deliveryReport>
<!--Optional:-->
<ns:validityPeriod>169</ns:validityPeriod>
<!--Optional:-->
<ns:tags>
<!--1 or more repetitions:-->
<ns:tag name="?">?</ns:tag>
</ns:tags>
</ns:message>
</ns:messages>
</ns:requestBody>
</ns:sendMessages>
</soapenv:Body>
</soapenv:Envelope>
you can ignore optional field in above request. FYI.. I have generated it from soap ui. Let me know your further issues.
One more thing, If you will wrap your client soap call in try block and catch it in your code, you wont get these unhandled exception, for example:
try{
$response = $client->__soapCall("sendMessages", array($params));
}
catch (SoapFault $exception) {
echo $exception;
}

Issue in passing parameters in soap call to wsdl in php

I having a wsdl file which look like in the below structure
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:not="http://notification.ws.api.com/">
<soapenv:Header/>
<soapenv:Body>
<not:getNotificationWS>
<!--Optional:-->
<notification>
<!--Zero or more repetitions:-->
<notificationList>
<!--Optional:-->
<email>?</email>
<!--Optional:-->
<phone>?</phone>
<userId>?</userId>
</notificationList>
</notification>
</not:getNotificationWS>
</soapenv:Body>
</soapenv:Envelope>
I am calling the above wsdl via soap in my php, below is the soapcall which i am trying to call the above wsdl.
$response = new SoapClient("http://127.0.0.1:8080/API/ws/TESTWS?wsdl");
try{
$soapstr = $response->__soapCall("getNotificationWS",array("parameters" => array( 'email' => "google#gmail.com",
'phone' => "1111111",
'userId' => "100"
)));
echo print_r($soapstr);
}catch (Exception $e){
echo $e->getMessage();
}
I am not getting any output or error. I i print my last request it return the below xml
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://notification.ws.api.easymed.com/">
<SOAP-ENV:Body>
<ns1:getNotificationWS />
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
How to send data inside the soap request in php suggest me.
Can't see your 'parameters' in the xml. You don't use notification neither notificationList
array ( 'notification' => array ( 'notificationList' => array ( 'phone' => 1111, 'userId' => 999 ) ) )

Categories