【问题标题】:SoapUI using nuSoap "Premature end of Content-Length delimited message body"SoapUI 使用 nuSoap“内容长度分隔的消息体过早结束”
【发布时间】:2014-01-02 01:21:44
【问题描述】:

我正在尝试使用 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。

我现在的代码是这样的:

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 给出了正确的答案和赏金,因为它帮助我弄清楚更换主机:)

【问题讨论】:

    标签: php wsdl soapui nusoap


    【解决方案1】:

    过去我也遇到过同样的问题,然后我创建了自己的 WebService 控制器库来处理 SOAP 输入/输出消息,它还根据 v1.2 规范生成 WSDL 文档。如果您愿意,可以避免这种麻烦并使用以下实用程序:

    http://asimishaq.com/resources/easy-soap-web-service-php

    您在示例中创建的服务类型可以在 只需 5 分钟。这就是使用简单的肥皂库的方法:

    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 函数中定义这些方法并完成。如果您在实施方面需要任何帮助,请告诉我。

    【讨论】:

    • 谢谢你的回复......你能不能更好地解释一下我如何实现这个库。我创建了一个名为 productlist.php 的 php 文件并将你的文件(WebServiceController.php,WSDLInfo)放入同一个文件夹...然后我在 RewriteBase / RewriteRule ^(.*)$ WebServiceController.php [L] 上更改 RewriteEngine 中的 .htaccess 但它给了我 404 错误...
    • 这里是 turorial asimishaq.com/resources/easy-soap-web-service-php 从错误 404 看来 .htaccess 文件无法找到 WebServiceController.php 提示:将 .htaccess 文件放在同一目录中
    • 我把它放在同一个目录下,它仍然给我 404
    • 好的。你能上网吗,我的 skype-id 是:asim-ishaq 和电子邮件:asim709(at)gmail(dot)com 让我远程查看问题
    • @smile-applications 我已经使用 SoapUI 检查了服务,并且控制器文件中的正则表达式存在一些问题。我已经更正了文件,现在使用该工具可以正常工作。 WSDL: asimishaq.com/dd/SOAPWeb?wsdl 重新下载库:asimishaq.com/uploads/php-easy-soap-webservice.zip
    【解决方案2】:

    已编辑答案:

    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 web 服务,则您现有的代码是用于的。

    【讨论】:

    • 感谢您的回复...我已经更改了我的代码并更改了soapUi的属性(请参阅我的编辑),但它仍然没有输出任何内容...我尝试了两个命名空间
    • 请尝试我在答案中编辑的另一件事。
    • 我不明白我必须做什么......我每次都得到同样的错误
    • 从你的代码中删除 $server->configureWSDL('hellowsdl', 'tns:hellowsdl');。
    • 哦,对不起,我不明白......它在浏览器中给了我这个错误:致命错误:调用 /membri/sitidicarde/soap/lib/nusoap 中未定义的方法 stdClass::addOperation() .php 在第 4472 行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-19
    • 2020-10-28
    • 2017-03-25
    相关资源
    最近更新 更多