我正在尝试使用nuSoap(0.9.5v)建立一个web服务,所以在我的productList.php中我写了这个
require_once("./lib/nusoap.php");
$server = new soap_server();
$server->configureWSDL('hellowsdl', 'tns:hellowsdl');
$server->register('hello', array('name' => 'xsd:string'), array('return' => 'xsd:string'), 'tns:hellowsdl', 'tns:hellowsdl#hello', 'rpc', 'encoded', 'Returns hello name');
function hello($name) { return 'Hello, ' . $name.' !!!'; }
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
它生成了这个WSDL:
<definitions 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/" xmlns:tns="tns:hellowsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="tns:hellowsdl">
<types>
<xsd:schema targetNamespace="tns:hellowsdl">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
</xsd:schema>
</types>
<message name="helloRequest">
<part name="name" type="xsd:string"/>
</message>
<message name="helloResponse">
<part name="return" type="xsd:string"/>
</message>
<portType name="hellowsdlPortType">
<operation name="hello">
<documentation>Returns hello name</documentation>
<input message="tns:helloRequest"/>
<output message="tns:helloResponse"/>
</operation>
</portType>
<binding name="hellowsdlBinding" type="tns:hellowsdlPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="hello">
<soap:operation soapAction="tns:hellowsdl#hello" style="rpc"/>
<input>
<soap:body use="encoded" namespace="tns:hellowsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="tns:hellowsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="hellowsdl">
<port name="hellowsdlPort" binding="tns:hellowsdlBinding">
<soap:address location="http://www.sitidicarde.altervista.org/soap/productlist.php"/>
</port>
</service>
</definitions>
现在,如果我在soapUI中创建一个链接到该WSDL的项目,它就会给我这个输入
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="tns:hellowsdl" xmlns:nam="NAMESPACE" xmlns:res="RESULT">
<soapenv:Header/>
<soapenv:Body>
<tns:hello soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<name xsi:type="xsd:string">ASD</name>
</tns:hello>
</soapenv:Body>
</soapenv:Envelope>
当我点击提交时,它没有给我输出和错误日志,上面写着:
Thu Jan 02 02:10:53 CET 2014:ERROR:org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 515; received: 271
org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 515; received: 271
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:178)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:197)
at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:155)
at org.apache.http.util.EntityUtils.toByteArray(EntityUtils.java:100)
at org.apache.http.entity.BufferedHttpEntity.<init>(BufferedHttpEntity.java:60)
at com.eviware.soapui.impl.wsdl.submit.transports.http.HttpMethodSupport.getResponseBody(HttpMethodSupport.java:281)
at com.eviware.soapui.impl.wsdl.submit.transports.http.support.methods.ExtendedPostMethod.getResponseBody(ExtendedPostMethod.java:128)
at com.eviware.soapui.impl.wsdl.submit.transports.http.SinglePartHttpResponse.<init>(SinglePartHttpResponse.java:49)
at com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments.WsdlSinglePartHttpResponse.<init>(WsdlSinglePartHttpResponse.java:36)
at com.eviware.soapui.impl.wsdl.submit.filters.HttpPackagingResponseFilter.wsdlRequest(HttpPackagingResponseFilter.java:71)
at com.eviware.soapui.impl.wsdl.submit.filters.HttpPackagingResponseFilter.afterAbstractHttpResponse(HttpPackagingResponseFilter.java:48)
at com.eviware.soapui.impl.wsdl.submit.filters.AbstractRequestFilter.afterRequest(AbstractRequestFilter.java:64)
at com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport.sendRequest(HttpClientRequestTransport.java:290)
at com.eviware.soapui.impl.wsdl.WsdlSubmit.run(WsdlSubmit.java:123)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
修改
我改变了我的soapUI的功能:
在我看来问题是soapUI在声明WSDL时没有找到声明的Input和Output。
现在我的代码是这样的:
require_once("./lib/nusoap.php");
$server = new soap_server();
$namespace = "tns:hellowsdl";
$server->configureWSDL('hellowsdl');
$server ->wsdl->schemaTargetNamespace = $namespace;
$server->register('hello', array('name' => 'xsd:string'), array('return' => 'xsd:string'), 'tns:hellowsdl', 'tns:hellowsdl#hello', 'rpc', 'encoded', 'Returns hello name');
function hello($name) { return 'Hello, ' . $name.' !!!'; }
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
问题可能在我的主人身上。我在Asim给出了正确的答案和赏金,因为它帮助我找到了改变主人:)
答案 0 :(得分:1)
我在过去遇到了同样的问题然后我创建了自己的WebService控制器库来处理SOAP输入/输出消息,它还根据v1.2规范生成WSDL文档。如果您愿意,可以避免这种麻烦并使用以下实用程序:
http://asimishaq.com/resources/easy-soap-web-service-php
您在示例中创建的服务类型可以在中实现 仅需5分钟。这就是使用easy soap库的方法:
class HelloService {
public function hello($str) {
return "Respone From web-service: Hello, world! " . $str;
}
public function WEB_SERVICE_INFO() {
$info = new WSDLInfo("HelloService");
$info->addMethod("hello","hello","str:string","string");
return $info;
}
}
在此处查看行动:
WSDL链接 http://www.asimishaq.com/uploads/web-services/HelloService?wsdl
人类可读方法信息链接 http://www.asimishaq.com/uploads/web-services/HelloService
您可以检查任何SOAP客户端中的WSDL链接并发送和接收消息。关于库的好处是你只需编写所需的类和函数,然后在WEB_SERVICE_INFO函数中定义这些方法并完成它。如果您在实施方面需要任何帮助,请告诉我。
答案 1 :(得分:0)
编辑答案:
require_once("./lib/nusoap.php");
$server = new soap_server();
$server->register('hello', array('name' => 'xsd:string'), array('return' => 'xsd:string'), 'tns:hellowsdl', 'tns:hellowsdl#hello', 'rpc', 'encoded', 'Returns hello name');
function hello($name) { return 'Hello, ' . $name.' !!!'; }
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
我已经编辑了你的代码,试试这个来生成你的wsdl并从soapui进行测试。
同样在尝试使用soap ui时,不要忘记将请求属性编码更改为“iso-8859-1”而不是“UTF-8”。
如果您使用现有的wsdl配置您的php webservice,那么您的现有代码适用。