代码摘要:
服务端(C#):
[WebService(Namespace="www.ah165.com")]
public class Service1 : System.Web.Services.WebService
{
public Service1(){ InitializeComponent();}
[WebMethod]
public string JouweiTest2(string hehe)
{
return "<"+hehe+">";
}}
客户端(php):
require('nusoap.php');
$s=new soapclient('http://localhost/WebServiceTest/Service1.asmx',true);
$s->soap_defencoding = 'UTF-8';
$result=$s->call('JouweiTest2', array('hehe' => '你好'),"www.ah165.com","www.ah165.com/JouweiTest2");
if (!$err=$s->getError()) {
echo '结果: '.$result;
} else {
echo '错误: '.$err;
}
echo "<xmp>".$s->request."</xmp><br><br>";
echo "<xmp>".$s->response."</xmp>";
执行结果:
结果: <>
POST /WebServiceTest/Service1.asmx HTTP/1.0
Host: localhost
User-Agent: NuSOAP/0.7.2 (1.95)
Content-Type: text/xml; charset=UTF-8
SOAPAction: "www.ah165.com/JouweiTest2"
Content-Length: 502
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns5838:JouweiTest2 xmlns:ns5838="www.ah165.com">
<hehe xsi:type="xsd:string">wbxan</hehe>
</ns5838:JouweiTest2>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Thu, 09 Feb 2006 02:58:06 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 358
<?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>
<JouweiTest2Response xmlns="www.ah165.com">
<JouweiTest2Result><></JouweiTest2Result>
</JouweiTest2Response>
</soap:Body>
</soap:Envelope>
-------------------------------
从上面的代码可以看出,服务器端接受到的参数hehe的值为空。
高手能解释一下问题出在那里吗?谢谢!
服务端(C#):
[WebService(Namespace="www.ah165.com")]
public class Service1 : System.Web.Services.WebService
{
public Service1(){ InitializeComponent();}
[WebMethod]
public string JouweiTest2(string hehe)
{
return "<"+hehe+">";
}}
客户端(php):
require('nusoap.php');
$s=new soapclient('http://localhost/WebServiceTest/Service1.asmx',true);
$s->soap_defencoding = 'UTF-8';
$result=$s->call('JouweiTest2', array('hehe' => '你好'),"www.ah165.com","www.ah165.com/JouweiTest2");
if (!$err=$s->getError()) {
echo '结果: '.$result;
} else {
echo '错误: '.$err;
}
echo "<xmp>".$s->request."</xmp><br><br>";
echo "<xmp>".$s->response."</xmp>";
执行结果:
结果: <>
POST /WebServiceTest/Service1.asmx HTTP/1.0
Host: localhost
User-Agent: NuSOAP/0.7.2 (1.95)
Content-Type: text/xml; charset=UTF-8
SOAPAction: "www.ah165.com/JouweiTest2"
Content-Length: 502
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns5838:JouweiTest2 xmlns:ns5838="www.ah165.com">
<hehe xsi:type="xsd:string">wbxan</hehe>
</ns5838:JouweiTest2>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Thu, 09 Feb 2006 02:58:06 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 358
<?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>
<JouweiTest2Response xmlns="www.ah165.com">
<JouweiTest2Result><></JouweiTest2Result>
</JouweiTest2Response>
</soap:Body>
</soap:Envelope>
-------------------------------
从上面的代码可以看出,服务器端接受到的参数hehe的值为空。
高手能解释一下问题出在那里吗?谢谢!
$result = $proxy->JouweiTest2($params);
我用getProxy 卻找不到方法.
似乎還有命名空間的問題
$client = new soapclient('http://tia.gncc.net/ws/hrmanager.asmx?WSDL', 'wsdl');
$client->soap_defencoding = 'utf-8';
$client->decode_utf8 = false;
$client->setDefaultRpcParams(true);
$params = array(
'account' => $loginid
);
$proxy = $client->getProxy();
$result = $proxy->GetUserInfoByAccount($params);
$document=$proxy->document;
echo $document;