高手赐教webservice 传入参数里有数组时,怎么写.下面部分代码.
<?phprequire_once('nusoap.php');//调用一个开源的类...
...
$info[0] = $street; // street1
$info[1] = ""; // street2
$info[2] = $city; // city
$info[3] = $state; // state
$info[4] = $zip; // zip
$info[5] = $country; // country
$param = array("username" => $username,"password"=>$password,"barefootAccount" => $account,"info"=>$info);
$result = $client->call($callFunction, array('parameters' => $param), '', '', false, true,'document','encoded');...
...?>
<?phprequire_once('nusoap.php');//调用一个开源的类...
...
$info[0] = $street; // street1
$info[1] = ""; // street2
$info[2] = $city; // city
$info[3] = $state; // state
$info[4] = $zip; // zip
$info[5] = $country; // country
$param = array("username" => $username,"password"=>$password,"barefootAccount" => $account,"info"=>$info);
$result = $client->call($callFunction, array('parameters' => $param), '', '', false, true,'document','encoded');...
...?>
$result = $client->call($callFunction, $param, '', '', false, true,'document','encoded');
这样不行?
require_once('nusoap.php'); /* Initialize parameter */
$namep = "your message or e-mail";
$param = array('String_1' => $namep); /* create client */
$endpoint = "http://www.pascalbotte.be/rcx-ws/rcx";
/* As mentionned as above, you can use the value Type namespace
you will find at the end of the report generated by my
free WSDL parser, see http://www.pascalbotte.be/service.php */
$mynamespace = "http://phonedirlux.homeip.net/types";
$client = new soapclient($endpoint); /* call readLS */
// specify the namespace as the thirthd param,
// enventually the soapAction as the fourth
// for a document/literal web service
$response = $client->call('readLS', $param, $mynamespace);
?>
html code...
<?=$response?>
html code...这里有教程,,,http://users.skynet.be/pascalbotte/rcx-ws-doc/phpclient.htm
http://www.batteries-retailing.com/nusoap.rar
Array
(
[faultcode] => soap:Server
[faultstring] => System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.TranslateFaultCode(XmlQualifiedName code)
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.WriteFault(XmlWriter writer, SoapException soapException, HttpStatusCode statusCode)
at System.Web.Services.Protocols.SoapServerProtocol.WriteException(Exception e, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteException(Exception e)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
--- End of inner exception stack trace ---
[detail] =>
)
<?php
require_once('nusoap.php');//调用一个开源的类$street="street1";
$city="ny";
$state="NY";
$zip="00000";
$country="US";
$lastname="L_name";
$firstname="F_name";
$propertyId="6865";$info[0] = $street; // street1
$info[1] = ""; // street2
$info[2] = $city; // city
$info[3] = $state; // state
$info[4] = $zip; // zip
$info[5] = $country; // country
$info[6] = $lastname; // lastname
$info[7] = $firstname; // firstname
$info[8] = ""; // homephone
$info[9] = ""; // bizphone
$info[10] = ""; // fax
$info[11] = ""; // mobile
$info[12] = ""; // email
$info[13] = $propertyId; // PropertyID$callFunction = "SetConsumerInfo";$param = array("username" => $username,"password"=>$password,"barefootAccount" => $account,"info"=> array("i0"=> $street,"i1"=> "","i2"=> $city,"i3"=> $state,"i4"=> $zip,"i5"=> $country,"i6"=> $lastname,"i7"=> $firstname,"i8"=> "","i9"=> "","i10"=> "","i11"=> "","i12"=> "","i13"=> $propertyId));
$result = $client->call($callFunction, $param, '', '', false, true,'document','encoded');
?>我这样写也不对,高手帮忙看下,怎么写.
<?php require_once('nusoap.php');//调用一个开源的类
$client = new soapclient($s_wsdl, true);
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$street="street1";
$city="ny";
$state="NY";
$zip="00000";
$country="US";
$lastname="L_name";
$firstname="F_name";
$propertyId="6865";
$info[0] = $street; // street1
$info[1] = ""; // street2
$info[2] = $city; // city
$info[3] = $state; // state
$info[4] = $zip; // zip
$info[5] = $country; // country
$info[6] = $lastname; // lastname
$info[7] = $firstname; // firstname
$info[8] = ""; // homephone
$info[9] = ""; // bizphone
$info[10] = ""; // fax
$info[11] = ""; // mobile
$info[12] = ""; // email
$info[13] = $propertyId; // PropertyID
$callFunction = "SetConsumerInfo";
// Doc/lit parameters get wrapped
$param = array("username" => $username,"password"=>$password,"barefootAccount" => $account,"info"=> array("i0"=> $street,"i1"=> "","i2"=> $city,"i3"=> $state,"i4"=> $zip,"i5"=> $country,"i6"=> $lastname,"i7"=> $firstname,"i8"=> "","i9"=> "","i10"=> "","i11"=> "","i12"=> "","i13"=> $propertyId));
$result = $client->call($callFunction, $param, '', '', false, true,'document','encoded');
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>这是我的全部代码,nusoap.php 可以在:http://www.batteries-retailing.com/nusoap.rar 下载
这样的参数传递方法是正确的,不用改,至于你的错误,我没看出原因,你把错误信息都贴出来了吗?
http://www.batteries-retailing.com/error.txt
Array
(
[faultcode] => soap:Server
[faultstring] => System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.TranslateFaultCode(XmlQualifiedName code)
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.WriteFault(XmlWriter writer, SoapException soapException, HttpStatusCode statusCode)
at System.Web.Services.Protocols.SoapServerProtocol.WriteException(Exception e, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteException(Exception e)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
--- End of inner exception stack trace ---
[detail] =>
)Request
POST /barefootwebservice/bookingAccess3.asmx HTTP/1.0
Host: agent3.barefoot.com
User-Agent: NuSOAP/0.7.3 (1.114)
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: "http://www.barefoot.com/Services/SetConsumerInfo"
Content-Length: 518Response
HTTP/1.1 500 Internal Server Error
Connection: close
Date: Sat, 10 Apr 2010 07:45:35 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Content-Length: 1147<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.TranslateFaultCode(XmlQualifiedName code)
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.WriteFault(XmlWriter writer, SoapException soapException, HttpStatusCode statusCode)
at System.Web.Services.Protocols.SoapServerProtocol.WriteException(Exception e, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteException(Exception e)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
--- End of inner exception stack trace ---</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>
這也讓我相當地鬱悶,而且還很莫名....
据说可能在不同系统间传递时数据类型会有区别可以看看参考wsdl文档定义,看看是否转化为相应的xml数据类型。(这个只是推测,如果实在找不到原因,可以看看这个)