- 论坛徽章:
- 0
|
本帖最后由 illidanee 于 2012-12-14 11:51 编辑
大家好,俺又来了.
最近使用perl发布webservice服务. 服务已经可以调通, 但是不知道怎么生成wsdl文档. 于是查找资料, 最中找到 WSDL::Generator 这个包.
先上服务器代码. (为了清晰,已经将其简化)
文件为 /cgi-bin/XmlData.pm;- #!/usr/bin/perl
- package XmlData;
- use strict;
- use warnings;
- sub getData {
- return "OK";
- }
- 1;
复制代码 服务器代理代码.
文件为 /cgi-bin/Static.cgi- #!/usr/bin/perl
- use strict;
- use warnings;
- use SOAP::Transport::HTTP;
- SOAP::Transport::HTTP::CGI->dispatch_to('XmlData')-> handle;
复制代码 使用 WSDL::Generator 创建wsdl代码
文件为 /cigb-bin/Static- #!/usr/bin/perl
- use WSDL::Generator;
- print "Content-type: text/html\n\n";
- my $init = {
- 'schema_namesp' => 'http://172.30.35.29:10000/cgi-bin/Static.xsd',
- 'services' => 'MyServices',
- 'service_name' => 'XmlData',
- 'target_namesp' => 'http://172.30.35.29:10000/cgi-bin',
- 'documentation' => 'Simple XML SOAP Service.',
- 'location' => 'http://172.30.35.29:10000/cgi-bin/Static.cgi'
- };
- my $w = WSDL::Generator->new($init);
- XmlData->getData();
- print $w->get("XmlData");
复制代码 使用浏览器打开
http://172.30.35.29:10000/cgi-bin/Static?wsdl
显示如下:- <?xml version="1.0" ?>
- - <definitions name="XmlData" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://172.30.35.29:10000/cgi-bin" xmlns:tns="http://172.30.35.29:10000/cgi-bin" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsdl="http://172.30.35.29:10000/cgi-bin/Static.xsd">
- - <types>
- - <xsd:schema targetNamespace="http://172.30.35.29:10000/cgi-bin/Static.xsd">
- <xsd:element name="getDataRequest" type="xsd:string" />
- <xsd:element name="getDataResponse" type="xsd:string" />
- </xsd:schema>
- </types>
- - <message name="getDataRequest">
- <part name="getDataRequestSoapMsg" element="xsdl:getDataRequest" />
- </message>
- - <message name="getDataResponse">
- <part name="getDataResponseSoapMsg" element="xsdl:getDataResponse" />
- </message>
- - <portType name="MyServicesXmlDataPortType">
- - <operation name="getData">
- <input message="tns:getDataRequest" />
- <output message="tns:getDataResponse" />
- </operation>
- </portType>
- - <binding name="MyServicesXmlDataBinding" type="tns:MyServicesXmlDataPortType">
- <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
- - <operation name="getData">
- <soap:operation style="document" soapAction="" />
- - <input>
- <soap:body use="literal" />
- </input>
- - <output>
- <soap:body use="literal" />
- </output>
- </operation>
- </binding>
- - <service name="XmlData">
- <documentation>Simple XML SOAP Service.</documentation>
- - <port name="MyServicesXmlDataPort" binding="tns:MyServicesXmlDataBinding">
- <soap:address location="http://172.30.35.29:10000/cgi-bin/Static.cgi" />
- </port>
- </service>
- </definitions>
复制代码 使用客户端测试- #!/usr/bin/perl
- use SOAP::Lite +debug;
- print SOAP::Lite
- ->service('http://172.30.35.29:10000/cgi-bin/Static?wsdl')
- ->getData();
复制代码 结果如下:- SOAP::Transport::HTTP::Client::new: ()
- SOAP::Lite::call: ()
- SOAP::Serializer::envelope: ()
- SOAP::Serializer::envelope: getData SOAP::Data=HASH(0x25fd428)
- SOAP::Data::new: ()
- SOAP::Data::new: ()
- SOAP::Data::new: ()
- SOAP::Data::new: ()
- SOAP::Data::new: ()
- SOAP::Transport::HTTP::Client::send_receive: HTTP::Request=HASH(0x2667d68)
- SOAP::Transport::HTTP::Client::send_receive: POST http://172.30.35.29:10000/cgi-bin/Static.cgi HTTP/1.1
- Accept: text/xml
- Accept: multipart/*
- Accept: application/soap
- Content-Length: 557
- Content-Type: text/xml; charset=utf-8
- SOAPAction: ""
- <?xml version="1.0" encoding="UTF-8"?><soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsdl="http://172.30.35.29:10000/cgi-bin/Static.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://172.30.35.29:10000/cgi-bin"><soap:Body><tns:getData><getDataRequest xsi:type="xsd:string">CITY</getDataRequest></tns:getData></soap:Body></soap:Envelope>
- SOAP::Transport::HTTP::Client::send_receive: HTTP::Response=HASH(0x26dc720)
- SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 500 Internal Server Error
- Connection: close
- Date: Fri, 14 Dec 2012 15:54:54 GMT
- Server: Apache/2.2.23 (Unix) mod_perl/2.0.7 Perl/v5.16.2
- Content-Length: 551
- Content-Type: text/xml; charset=utf-8
- Client-Date: Fri, 14 Dec 2012 15:54:54 GMT
- Client-Peer: 172.30.35.29:10000
- Client-Response-Num: 1
- SOAPServer: SOAP::Lite/Perl/0.715
- <?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Failed to access class (cgi-bin) at /usr/local/lib/perl5/site_perl/5.16.2/SOAP/Lite.pm line 2760.
- </faultstring></soap:Fault></soap:Body></soap:Envelope>
- SOAP::Deserializer::deserialize: ()
- SOAP::Parser::decode: ()
- SOAP::SOM::new: ()
- SOAP::SOM::DESTROY: ()
- SOAP::Lite::DESTROY: ()
- SOAP::Deserializer::DESTROY: ()
- SOAP::Parser::DESTROY: ()
- SOAP::Transport::DESTROY: ()
- SOAP::Transport::HTTP::Client::DESTROY: ()
- SOAP::Serializer::DESTROY: ()
- SOAP::Data::DESTROY: ()
- SOAP::Data::DESTROY: ()
- SOAP::Data::DESTROY: ()
- SOAP::Data::DESTROY: ()
- SOAP::Data::DESTROY: ()
- SOAP::Data::DESTROY: ()
复制代码 我的问题:
1.生成wsdl文档不是2.0规范.应该是1.1, 请问怎么样可以生成2.0规范的wsdl.
2.我使用wsdl调用web服务,显示找不到class,请问是什么地方存在问题?日志文件中并没有错误信息.只有访问记录.
3.请问大家都用什么方法实现wsdl,能够实现跨语言调用的.可以给我一些建议.
|
|