/    Sign up×
Community /Pin to ProfileBookmark

Soap passing parameter error

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.

[quote]

Error: Warning: Invalid argument supplied for foreach() in webservice.php on line 23

[/quote]

[code=php]<?
$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 />”;
?>[/code]

WSDL File:

[code]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>[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@dk_zero-coolJun 21.2010 — Well, I can't see where your "$result" object variable is from, but your problem is that you are trying to loop a variable that does not contain an array.

Try to make a var_dump($array) and you will see the problem.

Also try using the is_array() to check your variables before running a loop on them.
Copy linkTweet thisAlerts:
@ty44lerauthorJun 22.2010 — Well, I can't see where your "$result" object variable is from, but your problem is that you are trying to loop a variable that does not contain an array.

Try to make a var_dump($array) and you will see the problem.

Also try using the is_array() to check your variables before running a loop on them.[/QUOTE]

var_dump($array) resulted in:

object(stdClass)#1 (1) { ["GetWorkOrdersResult"]=> object(stdClass)#3 (0) { } }

I'm not sure if it has come to me yet what to do next??

Here's what I have now:
[code=php]<?
$client = new SoapClient("http://refrigerantcompliance/RefrigerantComplianceService/Service1.asmx?wsdl", array('cache_wsdl' => 0));
$result = $client->GetWorkOrders("31200");

print "<select name='workorder'><option>Please Select One</option>";
foreach($result as $k=>$v){
print "<option value="".$v->SRPWOHRID."">".$v->SRPWOHRID." - ".$v->Description."</option>";
}
print "</select><br />";

?>[/code]
Copy linkTweet thisAlerts:
@dk_zero-coolJun 22.2010 — Well the loop in your new example should work since the object $result contains one index "GetWorkOrdersResult", but the value of that index contains an empty object, in your case $v, from where you are trying to access indexes that does not exist, $v->SRPWOHRID and $v->Description.

In short, $result contains "GetWorkOrdersResult" ($v), but $result->GetWorkOrdersResult ($v) is empty.
×

Success!

Help @ty44ler spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...