Ty44ler Posted June 21, 2010 Share Posted June 21, 2010 I'm just trying to make a SOAP call that passes one parameter (customerNumber) and prints a dropdown box, but it's giving me an error in my source code. Error: Warning: Invalid argument supplied for foreach() in webservice.php on line 23 <? $client = new SoapClient("http://refrigerantcompliance/RefrigerantComplianceService/Service1.asmx?wsdl", array('cache_wsdl' => 0)); $params = array('customerNumber'=>'2'); $client->__soapCall("GetWorkOrders", $params); $array = $result->GetWorkOrdersResult->WorkOrderDAO; print "<select name='CustomerName'><option>Please Select One</option>"; foreach($array as $k=>$v){ print "<option value=\"".$v->SRPWOHRID."\">".$v->SRPWOHRID."</option>"; } print "</select><br />"; ?> WSDL File: POST /RefrigerantComplianceService/Service1.asmx HTTP/1.1 Host: refrigerantcompliance Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <GetWorkOrders xmlns="http://tempuri.org/"> <customerNumber>string</customerNumber> </GetWorkOrders> </soap12:Body> </soap12:Envelope> HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <GetWorkOrdersResponse xmlns="http://tempuri.org/"> <GetWorkOrdersResult> <WorkOrderDAO> <StatusCode>string</StatusCode> <SRPWOHRID>int</SRPWOHRID> <CompanyNumber>int</CompanyNumber> <DivisionNumber>int</DivisionNumber> <CustomerNumber>int</CustomerNumber> <RequestNo>int</RequestNo> <RequestorName>string</RequestorName> <AreaCode>string</AreaCode> <PhoneNo>string</PhoneNo> <Address1>string</Address1> <Address2>string</Address2> <City>string</City> <StateCode>string</StateCode> <ZipCode>string</ZipCode> <RequestType>string</RequestType> <CustomerPONumber>string</CustomerPONumber> <Description>string</Description> </WorkOrderDAO> <WorkOrderDAO> <StatusCode>string</StatusCode> <SRPWOHRID>int</SRPWOHRID> <CompanyNumber>int</CompanyNumber> <DivisionNumber>int</DivisionNumber> <CustomerNumber>int</CustomerNumber> <RequestNo>int</RequestNo> <RequestorName>string</RequestorName> <AreaCode>string</AreaCode> <PhoneNo>string</PhoneNo> <Address1>string</Address1> <Address2>string</Address2> <City>string</City> <StateCode>string</StateCode> <ZipCode>string</ZipCode> <RequestType>string</RequestType> <CustomerPONumber>string</CustomerPONumber> <Description>string</Description> </WorkOrderDAO> </GetWorkOrdersResult> </GetWorkOrdersResponse> </soap12:Body> </soap12:Envelope> Link to comment https://forums.phpfreaks.com/topic/205434-soap-problem/ Share on other sites More sharing options...
Ty44ler Posted June 21, 2010 Author Share Posted June 21, 2010 Nobody must be a fan of SOAP. Link to comment https://forums.phpfreaks.com/topic/205434-soap-problem/#findComment-1075149 Share on other sites More sharing options...
gizmola Posted June 21, 2010 Share Posted June 21, 2010 The error you got is because $array is not an array. I noticed that at minimum, you don't actually assign $result to anything so naturally it's not an object. Also, not sure why you are calling __soapCall here, when you should be able to do: $result = $client->GetWorkOrders(2); Link to comment https://forums.phpfreaks.com/topic/205434-soap-problem/#findComment-1075192 Share on other sites More sharing options...
Ty44ler Posted June 21, 2010 Author Share Posted June 21, 2010 The error you got is because $array is not an array. I noticed that at minimum, you don't actually assign $result to anything so naturally it's not an object. Also, not sure why you are calling __soapCall here, when you should be able to do: $result = $client->GetWorkOrders(2); Thanks for your help Giz! I noticed that nothing was assigned to $result after I posted it and couldn't edit it. I should have mentioned GetWorkOrders is passed a customer number as a string from the first drop-down and then will return a list of work orders for that customer. Does it need quotes around it because its a string instead of a number? Here's what it is now: $client = new SoapClient("http://refrigerantcompliance/RefrigerantComplianceService/Service1.asmx?wsdl", array('cache_wsdl' => 0)); $result = $client->GetWorkOrders('2'); print "<select name='CustomerName'><option>Please Select One</option>"; foreach($result as $k=>$v){ print "<option value=\"".$v->RequestorName."\">".$v->RequestorName."</option>"; } print "</select><br />"; I don't get the errors anymore but nothing is displayed in the dropdown menu. Link to comment https://forums.phpfreaks.com/topic/205434-soap-problem/#findComment-1075202 Share on other sites More sharing options...
gizmola Posted June 21, 2010 Share Posted June 21, 2010 PHP would typecast the 2 to a string, since that was required, but it's ok that you're making it a string AFAIK. Try print_r($result) and see what you have. I think there's a structure there you may have to unbundle, based on the wsdl you provided. Link to comment https://forums.phpfreaks.com/topic/205434-soap-problem/#findComment-1075218 Share on other sites More sharing options...
Ty44ler Posted June 21, 2010 Author Share Posted June 21, 2010 print_r($result): stdClass Object ( [GetWorkOrdersResult] => stdClass Object ( ) ) Link to comment https://forums.phpfreaks.com/topic/205434-soap-problem/#findComment-1075220 Share on other sites More sharing options...
Ty44ler Posted June 21, 2010 Author Share Posted June 21, 2010 I was mistaken, this is the WSDL file: <wsdl:definitions targetNamespace="http://tempuri.org/"> − <wsdl:types> − <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/"> − <s:element name="HelloWorld"> <s:complexType/> </s:element> − <s:element name="HelloWorldResponse"> − <s:complexType> − <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string"/> </s:sequence> </s:complexType> </s:element> − <s:element name="GetCustomers"> <s:complexType/> </s:element> − <s:element name="GetCustomersResponse"> − <s:complexType> − <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="GetCustomersResult" type="tns:ArrayOfCustomerDAO"/> </s:sequence> </s:complexType> </s:element> − <s:complexType name="ArrayOfCustomerDAO"> − <s:sequence> <s:element minOccurs="0" maxOccurs="unbounded" name="CustomerDAO" nillable="true" type="tns:CustomerDAO"/> </s:sequence> </s:complexType> − <s:complexType name="CustomerDAO"> − <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="StatusCode" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="CompanyNumber" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="DivisionNumber" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="CustomerNumber" type="s:int"/> <s:element minOccurs="0" maxOccurs="1" name="CustomerName" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="Address1" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="Address2" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="City" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="StateCode" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="ZipCode" type="s:string"/> </s:sequence> </s:complexType> − <s:element name="GetWorkOrders"> − <s:complexType> − <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="customerNumber" type="s:string"/> </s:sequence> </s:complexType> </s:element> − <s:element name="GetWorkOrdersResponse"> − <s:complexType> − <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="GetWorkOrdersResult" type="tns:ArrayOfWorkOrderDAO"/> </s:sequence> </s:complexType> </s:element> − <s:complexType name="ArrayOfWorkOrderDAO"> − <s:sequence> <s:element minOccurs="0" maxOccurs="unbounded" name="WorkOrderDAO" nillable="true" type="tns:WorkOrderDAO"/> </s:sequence> </s:complexType> − <s:complexType name="WorkOrderDAO"> − <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="StatusCode" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="SRPWOHRID" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="CompanyNumber" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="DivisionNumber" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="CustomerNumber" type="s:int"/> <s:element minOccurs="1" maxOccurs="1" name="RequestNo" type="s:int"/> <s:element minOccurs="0" maxOccurs="1" name="RequestorName" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="AreaCode" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="PhoneNo" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="Address1" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="Address2" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="City" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="StateCode" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="ZipCode" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="RequestType" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="CustomerPONumber" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="Description" type="s:string"/> </s:sequence> </s:complexType> </s:schema> </wsdl:types> − <wsdl:message name="HelloWorldSoapIn"> <wsdl:part name="parameters" element="tns:HelloWorld"/> </wsdl:message> − <wsdl:message name="HelloWorldSoapOut"> <wsdl:part name="parameters" element="tns:HelloWorldResponse"/> </wsdl:message> − <wsdl:message name="GetCustomersSoapIn"> <wsdl:part name="parameters" element="tns:GetCustomers"/> </wsdl:message> − <wsdl:message name="GetCustomersSoapOut"> <wsdl:part name="parameters" element="tns:GetCustomersResponse"/> </wsdl:message> − <wsdl:message name="GetWorkOrdersSoapIn"> <wsdl:part name="parameters" element="tns:GetWorkOrders"/> </wsdl:message> − <wsdl:message name="GetWorkOrdersSoapOut"> <wsdl:part name="parameters" element="tns:GetWorkOrdersResponse"/> </wsdl:message> − <wsdl:portType name="Service1Soap"> − <wsdl:operation name="HelloWorld"> <wsdl:input message="tns:HelloWorldSoapIn"/> <wsdl:output message="tns:HelloWorldSoapOut"/> </wsdl:operation> − <wsdl:operation name="GetCustomers"> <wsdl:input message="tns:GetCustomersSoapIn"/> <wsdl:output message="tns:GetCustomersSoapOut"/> </wsdl:operation> − <wsdl:operation name="GetWorkOrders"> <wsdl:input message="tns:GetWorkOrdersSoapIn"/> <wsdl:output message="tns:GetWorkOrdersSoapOut"/> </wsdl:operation> </wsdl:portType> − <wsdl:binding name="Service1Soap" type="tns:Service1Soap"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/> − <wsdl:operation name="HelloWorld"> <soap:operation soapAction="http://tempuri.org/HelloWorld" style="document"/> − <wsdl:input> <soap:body use="literal"/> </wsdl:input> − <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> − <wsdl:operation name="GetCustomers"> <soap:operation soapAction="http://tempuri.org/GetCustomers" style="document"/> − <wsdl:input> <soap:body use="literal"/> </wsdl:input> − <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> − <wsdl:operation name="GetWorkOrders"> <soap:operation soapAction="http://tempuri.org/GetWorkOrders" style="document"/> − <wsdl:input> <soap:body use="literal"/> </wsdl:input> − <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> − <wsdl:binding name="Service1Soap12" type="tns:Service1Soap"> <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/> − <wsdl:operation name="HelloWorld"> <soap12:operation soapAction="http://tempuri.org/HelloWorld" style="document"/> − <wsdl:input> <soap12:body use="literal"/> </wsdl:input> − <wsdl:output> <soap12:body use="literal"/> </wsdl:output> </wsdl:operation> − <wsdl:operation name="GetCustomers"> <soap12:operation soapAction="http://tempuri.org/GetCustomers" style="document"/> − <wsdl:input> <soap12:body use="literal"/> </wsdl:input> − <wsdl:output> <soap12:body use="literal"/> </wsdl:output> </wsdl:operation> − <wsdl:operation name="GetWorkOrders"> <soap12:operation soapAction="http://tempuri.org/GetWorkOrders" style="document"/> − <wsdl:input> <soap12:body use="literal"/> </wsdl:input> − <wsdl:output> <soap12:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> − <wsdl:service name="Service1"> − <wsdl:port name="Service1Soap" binding="tns:Service1Soap"> <soap:address location="http://refrigerantcompliance/RefrigerantComplianceService/Service1.asmx"/> </wsdl:port> − <wsdl:port name="Service1Soap12" binding="tns:Service1Soap12"> <soap12:address location="http://refrigerantcompliance/RefrigerantComplianceService/Service1.asmx"/> </wsdl:port> </wsdl:service> </wsdl:definitions> The other was the asmx web page that the GetWorkOrder function has. Link to comment https://forums.phpfreaks.com/topic/205434-soap-problem/#findComment-1075225 Share on other sites More sharing options...
gizmola Posted June 21, 2010 Share Posted June 21, 2010 How about print_r($result->GetWorkOrdersResult)? Link to comment https://forums.phpfreaks.com/topic/205434-soap-problem/#findComment-1075285 Share on other sites More sharing options...
Ty44ler Posted June 22, 2010 Author Share Posted June 22, 2010 How about print_r($result->GetWorkOrdersResult)? stdClass Object ( ) var_dump($result); object(stdClass)#1 (1) { ["GetWorkOrdersResult"]=> object(stdClass)#3 (0) { } } Link to comment https://forums.phpfreaks.com/topic/205434-soap-problem/#findComment-1075505 Share on other sites More sharing options...
Ty44ler Posted June 22, 2010 Author Share Posted June 22, 2010 Got it figured out. Thanks for your help Gizmola! $client = new SoapClient("http://refrigerantcompliance/RefrigerantComplianceService/Service1.asmx?wsdl", array('cache_wsdl' => 0, 'trace' => 1)); $result = $client->GetWorkOrders(array("customerNumber" => "31150")); $orders = $result->GetWorkOrdersResult->WorkOrderDAO; print "<select name='workorder'><option>Please Select One</option>"; foreach($orders as $k=>$v){ print "<option value=\"".$v->SRPWOHRID."\">".$v->SRPWOHRID." - ".$v->Description."</option>"; } print "</select><br />"; Link to comment https://forums.phpfreaks.com/topic/205434-soap-problem/#findComment-1075614 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.