nusoap對於php4來説是挺好的選擇.php5自帶soap
nusoap下載地址:http://sourceforge.net/projects/nusoap/
一:使用
將lib文件夾放在你的項目下,使用 require_once('lib/nusoap.php'); 引用
二:簡單調用
C#端
[WebMethod]
public
string
testsoup(
string
objTime)
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
return objTime+"我暈kao";
}
php端
<?
php
require_once
(
'
lib/nusoap.php
'
);
$client
=
new
soapclientw(
'
http://localhost/CDBWeb/Search/WebService/cp1897books.asmx?WSDL
'
,
true
);
$client
->
soap_defencoding
=
'
UTF-8
'
;
$client
->
decode_utf8
=
false
;
$err
=
$client
->
getError();
if
(
$err
) {
echo
'
<h2>Constructor error</h2><pre>
'
.
$err
.
'
</pre>
'
;
}
$ParamArr
=
array
(
'
objTime
'
=>
"
2008-03-05
"
,
);
$param
=
array
(
'
parameters
'
=>
$ParamArr
);
$result
=
$client
->
call(
'
testsoup
'
,
$param
,
''
,
''
,
false
,
true
);
if
(
$client
->
fault)
{
echo
'
<h2>Fault (This is expected)</h2><pre>
'
;
print_r
(
$result
);
echo
'
</pre>
'
;
}
else
{
$err
=
$client
->
getError();
if
(
$err
)
{
echo
'
<h2>Error</h2><pre>
'
.
$err
.
'
</pre>
'
;
}
else
{
echo
'
<h2>Result</h2><pre>
'
;
print_r
(
$result
);
echo
'
</pre>
'
;
}
}
?>
注意:當在php5下運行,發生soapclient無法打開的錯誤,因php5自帶soap,只須將lib/nusoap.php的soapclient改名即可(在調用時使用更改的名稱,上面php代碼使用了"soapclientw"),nusoap.php更該后的一些代碼片斷如下:
/
class
soapclientw
extends
nusoap_base {
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
var
$username
=
''
;
var
$password
=
''
;
var
$authtype
=
''
;
var
$requestHeaders
=
false
;
//
SOAP headers in request (text)
var
$responseHeaders
=
''
;
//
SOAP headers from response (incomplete namespace resolution) (text)
var
$document
=
''
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
function
soapclientw(
$endpoint
,
$wsdl
=
false
,
$proxyhost
=
false
,
$proxyport
=
false
,
$proxyusername
=
false
,
$proxypassword
=
false
,
$timeout
=
0
,
$response_timeout
=
30
){
$this
->
endpoint
=
$endpoint
;
$this
->
proxyhost
=
$proxyhost
;
$this
->
proxyport
=
$proxyport
;
$this
->
proxyusername
=
$proxyusername
;
$this
->
proxypassword
=
$proxypassword
;
$this
->
timeout
=
$timeout
;
$this
->
response_timeout
=
$response_timeout
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
make values
if
(
$wsdl
){
$this
->
endpointType
=
'
wsdl
'
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)