我之前从未使用过SOAP,而且我是Perl脚本的新手。
使用perl客户端调用SOAP wsdl服务(Strawberry Perl (64-bit) 5.18.2.2-64bit
)
以下是为“HelloWorld()
”简单方法编写的perl脚本,用于调用
use SOAP::Lite +trace;
my $client = SOAP::Lite->service(
'http://myhost:8080/mySoapDemo/services/simpleSoapApi?wsdl');
$result = $client->HelloWorld();
print "welcome message is: $result\n";
但未收到HelloWorld()
方法的欢迎讯息。
而不是像<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 :(得分: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>