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 use 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 also tried this for 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 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 new to Soap and I tried messing around (going through raw, printed XML) and it seems like it can't get this to work. Any understanding of what I may be doing wrong would be greatly appreciated.

+4
source share
2 answers

I think you need to take a closer look at the documentation (regarding 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 . Here's how I did it in a similar project. This may not be the best practice. SoapVar may be the best way to do this ( SoapVoar with ANY_XML ).

+10
source

try passing $client->CustomerSearch($CustomerSearch); or pass a string

0
source

Source: https://habr.com/ru/post/1481249/


All Articles