php写的soap客户端访问用gsoap(C++)建立的webservice服务端的问题【50分】
我用gsoap写的服务端和客户端。想见http://happyyourlife.spaces.live.com/blog/cns!C6D18F3A3C949232!431.entry
http://www.cppblog.com/qiujian5628/archive/2008/06/19/54019.html
C++开发的服务端和客户端,客户端访问服务端执行正常结果。我想用php做客户端访问gsoap的webservice。出现问题。
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't find <definitions> in 'http://localhost:8888/?wsdl' in F:\phpinstall\webroot\web\one.php:5 Stack trace: #0 F:\phpinstall\webroot\web\one.php(5): SoapClient->SoapClient('http://localhos...') #1 {main}
服务端情况:
Socket connection successful: master socket = 3
SOAP 1.1 fault: SOAP-ENV:Client [no subcode]
"Method 'ns1:httpserver' not implemented: method name or namespace not recognized"
Detail: [no detail]
我的WSDL文件:
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="httpserver"
targetNamespace="http://127.0.0.1/httpserver.wsdl"
xmlns:tns="http://127.0.0.1/httpserver.wsdl"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns="urn:httpserver"
xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/"
xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace="urn:httpserver"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns="urn:httpserver"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
</schema>
</types>
<message name="addRequest">
<part name="num1" type="xsd:double"/>
<part name="num2" type="xsd:double"/>
</message>
<message name="addResponse">
<part name="sum" type="xsd:double"/>
</message>
<portType name="httpserverPortType">
<operation name="add">
<documentation>Service definition of function ns__add</documentation>
<input message="tns:addRequest"/>
<output message="tns:addResponse"/>
</operation>
</portType>
<binding name="httpserver" type="tns:httpserverPortType">
<SOAP:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="add">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:httpserver" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:httpserver" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="httpserver">
<documentation>gSOAP 2.7.9l generated service definition</documentation>
<port name="httpserver" binding="tns:httpserver">
<SOAP:address location="http://127.0.0.1/httpserver.wsdl"/>
</port>
</service>
</definitions>
我的php客户端是add.php
<?php
$sum = 0;
$num1 = 2
$num2 = 3
$client=new SoapClient('http://localhost:8888/?wsdl');
echo("SOAP服务器提供的开放函数:");
//以下代码为我解决了问题,显示出传入参数的结构,并且更容易获得返回值的结构
echo("执行GetGUIDNode的结果:");
try {
$parameters=array('num1'=>1,'num2'=>2, 'sum'=>$sum);
$username = $proxy->ns__add($parameters);
} catch (SoapFault $fault){
echo "Fault! code:",$fault->faultcode,", string: ",$fault->faultstring;
}
情况跟这位的一样http://bytes.com/topic/php/answers/825390-problem-client-soap-php-server-gsoap-c
很是困惑。
灵位我把php客户端中采用unsoap会出现找不到出口函数add的情况,add.php客户端如下:
<?php
require_once('../../nusoap/lib/nusoap.php');
$url1="http://localhost:8888/?wsdl";
try {
$client = new nusoap_client($url1,true);
$sum = 0;
$num1 = 2;
$num2 = 3;
$param = array($num1,$num2,$sum);
print_r($param);
$ret=$client->call('ns__add', $param);
echo $ret;
print_r($param);
} catch (SoapFault $fault){
echo "Fault! code:",$fault->faultcode,", string: ",$fault->faultstring;
}
?>
执行结果:不出现错误,但是$ret=$client->call('ns__add', $param);找不到函数,不执行结果,具体输出如下:
Array ( [0] => 2 [1] => 3 [2] => 0 ) Array ( [0] => 2 [1] => 3 [2] => 0 )
请各位大哥不吝赐教,分少会再加。先谢谢了
[解决办法]
什么语言来调用,和调用什么语言没有多大的联系吧
同样是遵循SOAP协议的
你什么意思?