7

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.

Axel
  • 10,732
  • 2
  • 30
  • 43
  • hi i am also having the same issue. I tried what he(@denormalizer) suggested this is the problem Exception Error! SOAP-ERROR: Encoding: object hasn't 'any' property – user1187 Jan 06 '15 at 11:22
  • See the accepted answer below. – Axel Jan 06 '15 at 17:25
  • hi Axel i tried the below answer with CustomerSearchS its working but its not working with CustomerSearch because of i guess its showing error . I dont know is it because of that it showing error – user1187 Jan 06 '15 at 18:20
  • I recommend you open a new question with the code you are using. Be sure to include the complete code and the complete error messages you are receiving. – Axel Jan 06 '15 at 18:21
  • Solving your problem in comments on an unrelated question/answer is not really the best place to try and solve your issue. I encourage you to focus on the responses given on the question you've asked. I can't really help you as much as other whom are more experienced on this subject. – Axel Jan 06 '15 at 18:26
  • http://stackoverflow.com/questions/27653095/what-is-any-in-wsdl-and-how-i-can-call-a-wsdl-function-using-php this is my question i havent got proper answer – user1187 Jan 06 '15 at 18:28
  • I understand and I've seen your question. Please focus the discuss of your issue on your own question. Solving it in this comment section isn't the appropriate place. Someone will help you, just work with them :) – Axel Jan 06 '15 at 18:29

2 Answers2

13

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).

Community
  • 1
  • 1
denormalizer
  • 2,186
  • 3
  • 24
  • 36
  • Thanks, this let me down the right track. I updated your answer with the exact code that worked for me. I used the `CustomerSearchS` instead, as you can pass the XML as a string. I also used `addChild` to generate the correct XML format. – Axel May 17 '13 at 16:15
  • 1
    for me i am getting this error Exception Error! SOAP-ERROR: Encoding: object hasn't 'any' property – user1187 Jan 06 '15 at 10:49
  • $client->CustomerSearch($params); when i am calling CustomerSearch tell me the reson for that – user1187 Jan 06 '15 at 10:50
  • i mean what is any here – user1187 Jan 06 '15 at 10:50
  • I'm not entirely sure, I asked this question over 2 years ago. If you're having an issue and the above code isn't working, I'd recommend compiling the code you are using into a new question and asking it (including all the details of what you are trying to do). – Axel Jan 06 '15 at 18:18
0

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

Rahul11
  • 264
  • 1
  • 10
  • I've tried that. `$client->CustomerSearch($CustomerSearch)` returns an `Invalid XML Document` response. – Axel May 16 '13 at 20:00
  • $result = $client->CustomerSearch(array('xml' => 'string')); xml is defined as string – Rahul11 May 16 '13 at 20:20
  • The XML isn't a string, it's an array. I've tried passing the XML as a string, I've tried passing the XML through `new SoapVar(xml, XSD_STRING);$`, then passing it to the Soap method. – Axel May 16 '13 at 20:23