Garf Posted May 3, 2012 Share Posted May 3, 2012 Hi all, I'm a newbie in PHP trying to move away from the .net platform. I seem to have run into my first challenge passing a complex type back to my web service. The web service is a live test site to test against. I've tested the service on .net and it works fine...but I think I'm missing something as I try porting over to PHP? I've written some short code to keep it simple: <?php $SearchCriteria = array("ObjectType"=>1); $parameters['user'] = "johndoe1"; $parameters['password'] = "snowball"; $parameters['SearchCriteria'] = $SearchCriteria ; $client = new SoapClient("https://servicestest.mcquaig.com/mws.asmx?WSDL"); $result = $client->__soapCall('Find', $parameters); ?> ....against this portion of XML: <s:element name="Find"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="user" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="criteria" type="tns:SearchCriteria"/> </s:sequence> </s:complexType> </s:element> <s:complexType name="SearchCriteria"> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="AccountName" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="ApplySharing" type="s:boolean"/> <s:element minOccurs="1" maxOccurs="1" name="CGType" type="s:int"/> <s:element minOccurs="0" maxOccurs="1" name="ClientRefID" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="Composites" type="s:int"/> <s:element minOccurs="0" maxOccurs="1" name="ConfNo" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="Email" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="Expired" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="ExpiryTSA" type="s:dateTime"/> <s:element minOccurs="1" maxOccurs="1" name="ExpiryTSZ" type="s:dateTime"/> <s:element minOccurs="0" maxOccurs="1" name="FirstName" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="FormLangID" type="s:unsignedLong"/> <s:element minOccurs="1" maxOccurs="1" name="FunctionalArea" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="Gender" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="Industry" type="s:int"/> <s:element minOccurs="0" maxOccurs="1" name="JobTitle" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="LastName" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="LastUsedTSA" type="s:dateTime"/> <s:element minOccurs="1" maxOccurs="1" name="LastUsedTSZ" type="s:dateTime"/> <s:element minOccurs="1" maxOccurs="1" name="NoRelated" type="s:boolean"/> <s:element minOccurs="1" maxOccurs="1" name="ObjectType" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="OrgID" type="s:unsignedLong"/> <s:element minOccurs="1" maxOccurs="1" name="Position" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="ProfileType" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="Recursive" type="s:boolean"/> <s:element minOccurs="1" maxOccurs="1" name="Status" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="Type" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="UnitsRemain" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="UnitsRemainGT" type="s:boolean"/> </s:sequence> </s:complexType> Nothing I seem to do works. I end up with the same error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Value does not fall within the expected range. Using NuSoap as: <?php require_once('lib/nusoap.php'); $SearchCriteria = array("ObjectType"=>1); $wsdlURL = "https://servicestest.mcquaig.com/mws.asmx?WSDL"; $soap = new nusoap_client($wsdlURL); $parameters['user'] = "johndoe1"; $parameters['password'] = "snowball"; $parameters['criteria'] = $SearchCriteria ; $result = $soap->call("Find", $parameters); if($error = $soap->getError()){ die($error);} ?> I get this error: soap:Client: Server did not recognize the value of HTTP Header SOAPAction: . I'm stumped and sure it's something small, but I just don't see what I'm missing?? Any suggestions are greatly appreciated!! Gary Quote Link to comment https://forums.phpfreaks.com/topic/262031-simple-soap-call-to-net-service/ Share on other sites More sharing options...
sanchez77 Posted May 3, 2012 Share Posted May 3, 2012 I have done little with SOAP, but the little I did, I wrote the call like this instead of using parameters. Hope this helps. $user= "johndoe1"; $password= "snowball"; $SearchCriteria ; $client = new SoapClient("https://servicestest.mcquaig.com/mws.asmx?WSDL"); $result= $client->Find(array('user'=>$user,'password'=>$password,'criteria'=>$SearchCriteria)); Quote Link to comment https://forums.phpfreaks.com/topic/262031-simple-soap-call-to-net-service/#findComment-1342825 Share on other sites More sharing options...
codebyren Posted May 3, 2012 Share Posted May 3, 2012 Judging by the WSDL, it looks like there are some required fields where the SearchCriteria array is concerned. For example, the ExpiryTSA field must apparently occur once, and only once, in the request: <s:element minOccurs="1" maxOccurs="1" name="ExpiryTSA" type="s:dateTime"/> If you create an array with all the required fields and add some test values (appropriately cast as integers or strings etc.) then you should get a response. I also had to guess that they wanted ISO 8601 format for the datetime fields. Using the following, I can at least get an empty result (hopefully you know better values to enter in each field): <?php $client = new SoapClient('https://servicestest.mcquaig.com/mws.asmx?WSDL'); $criteria = array( 'ApplySharing' => true, 'CGType' => 1, 'Composites' => 2, 'Expired' => 123, 'ExpiryTSA' => date('c'), 'ExpiryTSZ' => date('c'), 'FormLangID' => 123, 'FunctionalArea' => 5, 'Gender' => 2, 'Industry' => 2, 'LastUsedTSA' => date('c'), 'LastUsedTSZ' => date('c'), 'NoRelated' => true, 'ObjectType' => 1, 'OrgID' => 123, 'Position' => 3, 'ProfileType' => 1, 'Recursive' => true, 'Status' => 2, 'Type' => 2, 'UnitsRemain' => 2, 'UnitsRemainGT' => true ); $params = array('user' => 'johndoe1', 'password' => 'snowball', 'criteria' => $criteria); $result = $client->Find($params); print_r($result); ?> Quote Link to comment https://forums.phpfreaks.com/topic/262031-simple-soap-call-to-net-service/#findComment-1342852 Share on other sites More sharing options...
Garf Posted May 4, 2012 Author Share Posted May 4, 2012 Can't thank you enough for the responses and help! I would never have followed that route simply because I was verbally told the only required element was the "ObjectType". I also wasn't aware that the Min and Max was responsible for this. Interesting though, I am able to only pass one criteria when I build a client in c# using Visual Studio. I wonder if MS has some sort of proprietary method that makes it work vs. PHP? Thanks again! Gary Quote Link to comment https://forums.phpfreaks.com/topic/262031-simple-soap-call-to-net-service/#findComment-1342910 Share on other sites More sharing options...
codebyren Posted May 4, 2012 Share Posted May 4, 2012 I am able to only pass one criteria when I build a client in c# using Visual Studio. I wonder if MS has some sort of proprietary method that makes it work vs. PHP? I'm not really sure. I recall using a library in Python that could inspect the WSDL, generate a properly constructed object from it and then I'd just populate whatever properties I needed to (or had to) before making the SOAP call. Maybe c# has a similar implementation. It might just be that the fields/properties need to be present - regardless of whether they all have a value or not. I guess this depends on the SOAP server. Maybe someone else will shed some light on this... Quote Link to comment https://forums.phpfreaks.com/topic/262031-simple-soap-call-to-net-service/#findComment-1342912 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.