Вопрос

I'm trying to set up a webservice using nuSoap (0.9.5v), so in my productList.php I wrote this

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);

And it generate this 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>

Now, if I create a project in soapUI linked to that WSDL it gives me this input

<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>

And when I click submit it gives me no output and a Error Log that says:

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)

EDIT

I change my soapUI's poperties like this: enter image description here enter image description here

In my opinion the problem is that soapUI doesn't find an Input and an Output declared when instead in the WSDL are declared.

And my code now is this:

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);

Probrably the problem is in my host. I gave at Asim the correct answer and the bounty becaude it helped me to figure out to change host :)

Это было полезно?

Решение

I have the same issue in the Past and then I created my own WebService controller library that handles SOAP in/out messages and it also generates WSDL document according to v1.2 specs. If you like you can avoid this hassle and use the following utility:

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

The type of service you are creating in example can be implemented in just 5 mins. This is how it can be done using easy soap library:

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;
    }
}

See it in Action here:

WSDL Link http://www.asimishaq.com/uploads/web-services/HelloService?wsdl

Human Readable Method Information link http://www.asimishaq.com/uploads/web-services/HelloService

You may check the WSDL link in any SOAP client and send and receive messages. The good thing about the library is that you just write your required class and functions and then define these methods in WEB_SERVICE_INFO function and its done. Let me know if you need any help in implementation.

Другие советы

edited Answer:

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);

I have edited your code, Try this to generate your wsdl and test from soapui.

Also while trying from soap ui, don't forget to change request property Encoding as "iso-8859-1" instead of "UTF-8".

your existing code is for,if you are configuring your php webservice using an existing wsdl.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top