Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending XML input to WSDL using SoapClient

I have this WSDL: https://secure.softwarekey.com/solo/webservices/XmlCustomerService.asmx?WSDL

I am trying to use SoapClient to send a request to the CustomerSearch method.

The code I'm using is as follows:

$url = 'https://secure.softwarekey.com/solo/webservices/XmlCustomerService.asmx?WSDL';
$client = new SoapClient($url);

$CustomerSearch = array(
    'AuthorID' => $authorID,
    'UserID' => $userID,
    'UserPassword' => $userPassword,
    'Email' => $customerEmail 
);

$xml = array('CustomerSearch' => $CustomerSearch);

$result = $client->CustomerSearch(array('xml' => $xml));

When I run the code, I get the following PHP exception:

Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object has no 'any' property

I have also tried this for the XML:

$xml = "
<?xml version=\"1.0\" encoding=\"utf-8\"?> 
<CustomerSearch>
    <AuthorID>$authorID</AuthorID>
    <UserID>$userID</UserID>
    <UserPassword>$userPassword</UserPassword>
    <Email>$customerEmail</Email>
</CustomerSearch>
";

Which gives me the following results (from a print_r):

object(stdClass)#4 (1) { ["CustomerSearchResult"]=> object(stdClass)#5 (1) { ["any"]=> string(108) "-2Invalid Xml Document" } }

The documentation says that the input XML should look something like this:

<CustomerSearch>
<AuthorID></AuthorID>
<UserID></UserID>
<UserPassword></UserPassword>
<SearchField></SearchField>
<SearchField></SearchField>
<!-- ...additional SearchField elements -->
</CustomerSearch> 

I'm fairly new to Soap and I've tried messing around (passing in raw, typed out XML), and can't seem to get this to work. Any insight on what I may be doing wrong would be greatly appreciated.

like image 793
Axel Avatar asked May 16 '13 19:05

Axel


1 Answers

I think you need to look more into the documentation (with regards to the any parameter). But your request should be something like this:

$url = 'https://secure.softwarekey.com/solo/webservices/XmlCustomerService.asmx?WSDL';
$client = new SoapClient($url);

$xmlr = new SimpleXMLElement("<CustomerSearch></CustomerSearch>");
$xmlr->addChild('AuthorID', $authorID);
$xmlr->addChild('UserID', $userID);
$xmlr->addChild('UserPassword', $userPassword);
$xmlr->addChild('Email', $customerEmail);

$params = new stdClass();
$params->xml = $xmlr->asXML();

$result = $client->CustomerSearchS($params);

EDIT: This is how I've done it in similar project. It may not be best practice. SoapVar might be the better way to do it (SoapVoar example with ANY_XML).

like image 177
denormalizer Avatar answered Oct 23 '22 03:10

denormalizer