2014-07-22 28 views
1

我從來沒有使用過SOAP,我對Perl腳本有點新鮮。SOAP API wsdl使用perl的服務調用

SOAP WSDL服務用perl客戶端(Strawberry Perl (64-bit) 5.18.2.2-64bit) 在呼叫是爲 「HelloWorld()」 簡單的方法寫入調用

use SOAP::Lite +trace; 

Perl腳本 - 加載WSDL文檔

my $client = SOAP::Lite->service(
     'http://myhost:8080/mySoapDemo/services/simpleSoapApi?wsdl'); 

- 撥打RPC

$result = $client->HelloWorld(); 

- 顯示結果

print "welcome message is: $result\n"; 

但是沒有得到HelloWorld()方法的歡迎消息。 不但得不到XML像<faultcode><faultstring>

以下是命令行跟蹤代碼,這有助於問題域:

<?xml version="1.0" encoding="UTF-8"?><soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://soap.corporate.j2.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/X 
MLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><tns:HelloWorld xsi:nil="true" /></soap:Body></soap:Envelope> 
SOAP::Transport::HTTP::Client::send_receive: HTTP::Response=HASH(0x303f18) 
SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 500 Internal Server Error 
Connection: close 
Date: Tue, 22 Jul 2014 05:21:51 GMT 
Server: Apache-Coyote/1.1 
Content-Length: 328 
Content-Type: text/xml;charset=UTF-8 
Client-Date: Tue, 22 Jul 2014 05:21:52 GMT 
Client-Peer: 127.0.0.1:6060 
Client-Response-Num: 1 

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>wrong number of arguments while invoking public java.lang.String com.myFirst.soap.HelloWorld() with params [null].</faultstring></soap:Fault></soap:Body></soap:Envelope> 
SOAP::Deserializer::deserialize:() 
SOAP::Parser::decode:() 
SOAP::SOM::new:() 
SOAP::SOM::DESTROY:() 
welcome message is: 
SOAP::Lite::DESTROY:() 
SOAP::Serializer::DESTROY:() 
SOAP::Data::DESTROY:() 
SOAP::Data::DESTROY:() 
SOAP::Data::DESTROY:() 
SOAP::Data::DESTROY:() 
SOAP::Deserializer::DESTROY:() 
SOAP::Parser::DESTROY:() 
SOAP::Transport::DESTROY:() 
SOAP::Transport::HTTP::Client::DESTROY:() 
SOAP::Data::DESTROY:() 
SOAP::Data::DESTROY:() 
SOAP::Data::DESTROY:() 

請大家幫我出了什麼與腳本腳麻。 在此先感謝..

請找到WSDL:

<wsdl:definitions name="simpleSoapDemo" targetNamespace="http://soap.exampleNameSpace.com"> 
<wsdl:types> 
<xs:schema elementFormDefault="unqualified" targetNamespace="http://soap.exampleNameSpace.com" version="1.0"> 
<xs:element name="HelloWorld" type="tns:HelloWorld"/> 
<xs:element name="HelloWorldResponse" type="tns:HelloWorldResponse"/> 
<xs:complexType name="HelloWorld"><xs:sequence/></xs:complexType> 
<xs:complexType name="HelloWorldResponse"> 
<xs:sequence><xs:element minOccurs="0" name="return" type="xs:string"/></xs:sequence> 
</xs:complexType> 
</xs:schema> 
</wsdl:types> 
<wsdl:message name="HelloWorld"> 
<wsdl:part element="tns:HelloWorld" name="parameters"> 
</wsdl:part> 
</wsdl:message> 
<wsdl:message name="HelloWorldResponse"> 
<wsdl:part element="tns:HelloWorldResponse" name="parameters"> 
</wsdl:part> 
</wsdl:message> 
<wsdl:portType name="SimpleSoapApiServiceWsdlEndpoint"> 
<wsdl:operation name="HelloWorld"><wsdl:input message="tns:HelloWorld" name="HelloWorld"> 
</wsdl:input><wsdl:output message="tns:HelloWorldResponse" name="HelloWorldResponse"> 
</wsdl:output></wsdl:operation></wsdl:portType> 
<wsdl:binding name="simpleSoapDemoSoapBinding" type="tns:SimpleSoapApiServiceWsdlEndpoint"><soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
<wsdl:operation name="HelloWorld"><soap:operation soapAction="" style="document"/><wsdl:input name="HelloWorld"><soap:body use="literal"/></wsdl:input><wsdl:output name="HelloWorldResponse"><soap:body use="literal"/></wsdl:output></wsdl:operation> 
<wsdl:service name="simpleSoapDemo"><wsdl:port binding="tns:simpleSoapDemoSoapBinding" name="simpleSoapDemoSoapApiServiceWsdlPort"><soap:address location="http://myhost:8080/mySoapDemo/services/simpleSoapApi"/></wsdl:port></wsdl:service></wsdl:definitions> 
+0

看起來像被參數丟失。你可以添加wsdl嗎? – Jens

+0

您好Jens感謝您的回覆!我添加了缺少的WSDL請查找相同。 – Skumar

回答

1

看起來你的WSDL是不正確的。

能否請您嘗試以下:

<?xml version="1.0" encoding="UTF-8"?> 
<wsdl:definitions name="simpleSoapDemo" targetNamespace="http://soap.exampleNameSpace.com" xmlns:tns="http://soap.exampleNameSpace.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> 
    <wsdl:types> 

     <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" 
      targetNamespace="http://soap.exampleNameSpace.com" version="1.0"> 
      <xs:element name="HelloWorld" type="tns:HelloWorld" /> 
      <xs:element name="HelloWorldResponse" type="tns:HelloWorldResponse" /> 
      <xs:complexType name="HelloWorldResponse"> 
       <xs:sequence> 
        <xs:element minOccurs="0" name="return" type="xs:string" /> 
       </xs:sequence> 
      </xs:complexType> 
     </xs:schema> 
     </wsdl:types> 
    <wsdl:message name="HelloWorldRequest"> 
    </wsdl:message> 
    <wsdl:message name="HelloWorldResponse"> 
     <wsdl:part element="tns:HelloWorldResponse" name="parameters"> 
     </wsdl:part> 
    </wsdl:message> 
    <wsdl:portType name="SimpleSoapApiServiceWsdlEndpoint"> 
     <wsdl:operation name="HelloWorld"> 
      <wsdl:input message="tns:HelloWorldRequest" name="HelloWorld"> 
      </wsdl:input> 
      <wsdl:output message="tns:HelloWorldResponse" name="HelloWorldResponse"> 
      </wsdl:output> 
     </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="simpleSoapDemoSoapBinding" type="tns:SimpleSoapApiServiceWsdlEndpoint"> 
     <soap:binding style="document" 
      transport="http://schemas.xmlsoap.org/soap/http" /> 
     <wsdl:operation name="HelloWorld"> 
      <soap:operation soapAction="" style="document" /> 
      <wsdl:input name="HelloWorldRequest"> 
       <soap:body use="literal" /> 
      </wsdl:input> 
      <wsdl:output name="HelloWorldResponse"> 
       <soap:body use="literal" /> 
      </wsdl:output> 
     </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="simpleSoapDemo"> 
      <wsdl:port binding="tns:simpleSoapDemoSoapBinding" name="simpleSoapDemoSoapApiServiceWsdlPort"> 
       <soap:address location="http://myhost:8080/mySoapDemo/services/simpleSoapApi" /> 
      </wsdl:port> 
     </wsdl:service> 
</wsdl:definitions> 
+0

感謝Jens爲您提供的答覆將盡快啓動,並讓您知道是否仍然需要任何幫助!... – Skumar

+0

感謝Jens對我的工作問題在於WSDL創建。由於擁有<15的聲譽我無法欣賞。非常感謝 !.. – Skumar