免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2881 | 回复: 2
打印 上一主题 下一主题

Perl 使用 WSDL::Generator 创建 wsdl 的几个问题. [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-12-14 11:49 |只看该作者 |倒序浏览
本帖最后由 illidanee 于 2012-12-14 11:51 编辑

大家好,俺又来了.



最近使用perl发布webservice服务. 服务已经可以调通, 但是不知道怎么生成wsdl文档. 于是查找资料, 最中找到 WSDL::Generator 这个包.

先上服务器代码. (为了清晰,已经将其简化)

文件为 /cgi-bin/XmlData.pm;
  1. #!/usr/bin/perl  

  2. package XmlData;
  3. use strict;
  4. use warnings;

  5. sub getData {
  6.         return "OK";
  7. }           

  8. 1;
复制代码
服务器代理代码.
文件为 /cgi-bin/Static.cgi
  1. #!/usr/bin/perl  
  2. use strict;
  3. use warnings;

  4. use SOAP::Transport::HTTP;
  5. SOAP::Transport::HTTP::CGI->dispatch_to('XmlData')-> handle;
复制代码
使用 WSDL::Generator 创建wsdl代码
文件为 /cigb-bin/Static
  1. #!/usr/bin/perl
  2. use WSDL::Generator;
  3. print "Content-type: text/html\n\n";
  4. my $init = {
  5.         'schema_namesp' => 'http://172.30.35.29:10000/cgi-bin/Static.xsd',
  6.         'services'      => 'MyServices',
  7.         'service_name'  => 'XmlData',
  8.         'target_namesp' => 'http://172.30.35.29:10000/cgi-bin',
  9.         'documentation' => 'Simple XML SOAP Service.',
  10.         'location'      => 'http://172.30.35.29:10000/cgi-bin/Static.cgi'
  11. };
  12. my $w = WSDL::Generator->new($init);
  13. XmlData->getData();
  14. print $w->get("XmlData");
复制代码
使用浏览器打开
http://172.30.35.29:10000/cgi-bin/Static?wsdl
显示如下:
  1.   <?xml version="1.0" ?>
  2. - <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">
  3. - <types>
  4. - <xsd:schema targetNamespace="http://172.30.35.29:10000/cgi-bin/Static.xsd">
  5.   <xsd:element name="getDataRequest" type="xsd:string" />
  6.   <xsd:element name="getDataResponse" type="xsd:string" />
  7.   </xsd:schema>
  8.   </types>
  9. - <message name="getDataRequest">
  10.   <part name="getDataRequestSoapMsg" element="xsdl:getDataRequest" />
  11.   </message>
  12. - <message name="getDataResponse">
  13.   <part name="getDataResponseSoapMsg" element="xsdl:getDataResponse" />
  14.   </message>
  15. - <portType name="MyServicesXmlDataPortType">
  16. - <operation name="getData">
  17.   <input message="tns:getDataRequest" />
  18.   <output message="tns:getDataResponse" />
  19.   </operation>
  20.   </portType>
  21. - <binding name="MyServicesXmlDataBinding" type="tns:MyServicesXmlDataPortType">
  22.   <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
  23. - <operation name="getData">
  24.   <soap:operation style="document" soapAction="" />
  25. - <input>
  26.   <soap:body use="literal" />
  27.   </input>
  28. - <output>
  29.   <soap:body use="literal" />
  30.   </output>
  31.   </operation>
  32.   </binding>
  33. - <service name="XmlData">
  34.   <documentation>Simple XML SOAP Service.</documentation>
  35. - <port name="MyServicesXmlDataPort" binding="tns:MyServicesXmlDataBinding">
  36.   <soap:address location="http://172.30.35.29:10000/cgi-bin/Static.cgi" />
  37.   </port>
  38.   </service>
  39.   </definitions>
复制代码
使用客户端测试
  1. #!/usr/bin/perl

  2. use SOAP::Lite +debug;

  3. print SOAP::Lite
  4.         ->service('http://172.30.35.29:10000/cgi-bin/Static?wsdl')
  5.         ->getData();
复制代码
结果如下:
  1. SOAP::Transport::HTTP::Client::new: ()
  2. SOAP::Lite::call: ()
  3. SOAP::Serializer::envelope: ()
  4. SOAP::Serializer::envelope: getData SOAP::Data=HASH(0x25fd428)
  5. SOAP::Data::new: ()
  6. SOAP::Data::new: ()
  7. SOAP::Data::new: ()
  8. SOAP::Data::new: ()
  9. SOAP::Data::new: ()
  10. SOAP::Transport::HTTP::Client::send_receive: HTTP::Request=HASH(0x2667d68)
  11. SOAP::Transport::HTTP::Client::send_receive: POST http://172.30.35.29:10000/cgi-bin/Static.cgi HTTP/1.1
  12. Accept: text/xml
  13. Accept: multipart/*
  14. Accept: application/soap
  15. Content-Length: 557
  16. Content-Type: text/xml; charset=utf-8
  17. SOAPAction: ""

  18. <?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>
  19. SOAP::Transport::HTTP::Client::send_receive: HTTP::Response=HASH(0x26dc720)
  20. SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 500 Internal Server Error
  21. Connection: close
  22. Date: Fri, 14 Dec 2012 15:54:54 GMT
  23. Server: Apache/2.2.23 (Unix) mod_perl/2.0.7 Perl/v5.16.2
  24. Content-Length: 551
  25. Content-Type: text/xml; charset=utf-8
  26. Client-Date: Fri, 14 Dec 2012 15:54:54 GMT
  27. Client-Peer: 172.30.35.29:10000
  28. Client-Response-Num: 1
  29. SOAPServer: SOAP::Lite/Perl/0.715

  30. <?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.
  31. </faultstring></soap:Fault></soap:Body></soap:Envelope>
  32. SOAP::Deserializer::deserialize: ()
  33. SOAP::Parser::decode: ()
  34. SOAP::SOM::new: ()
  35. SOAP::SOM::DESTROY: ()
  36. SOAP::Lite::DESTROY: ()
  37. SOAP::Deserializer::DESTROY: ()
  38. SOAP::Parser::DESTROY: ()
  39. SOAP::Transport::DESTROY: ()
  40. SOAP::Transport::HTTP::Client::DESTROY: ()
  41. SOAP::Serializer::DESTROY: ()
  42. SOAP::Data::DESTROY: ()
  43. SOAP::Data::DESTROY: ()
  44. SOAP::Data::DESTROY: ()
  45. SOAP::Data::DESTROY: ()
  46. SOAP::Data::DESTROY: ()
  47. SOAP::Data::DESTROY: ()
复制代码
我的问题:

  1.生成wsdl文档不是2.0规范.应该是1.1, 请问怎么样可以生成2.0规范的wsdl.

  2.我使用wsdl调用web服务,显示找不到class,请问是什么地方存在问题?日志文件中并没有错误信息.只有访问记录.

  3.请问大家都用什么方法实现wsdl,能够实现跨语言调用的.可以给我一些建议.

论坛徽章:
0
2 [报告]
发表于 2012-12-14 19:01 |只看该作者
太长了。
友情帮顶

论坛徽章:
0
3 [报告]
发表于 2012-12-17 10:05 |只看该作者
cuteorange 发表于 2012-12-14 19:01
太长了。
友情帮顶




非常感谢支持的朋友,

经过许多朋友的帮助,我终于调通了.上面的代码生成wsdl部分修改如下即可调通.
  1. #!/usr/bin/perl
  2. use WSDL::Generator;
  3. print "Content-type: text/html\n\n";
  4. my $init = {
  5.         'schema_namesp' => 'http://172.30.35.29:10000/cgi-bin/Static.xsd',
  6.         'services'      => 'MyServices',
  7.         'service_name'  => 'XmlData',
  8.         'target_namesp' => 'http://172.30.35.29:10000/cgi-bin/Static.cgi',
  9.         'documentation' => 'Simple XML SOAP Service.',
  10.         'location'      => 'http://172.30.35.29:10000/cgi-bin/Static?wsdl'
  11. };
  12. my $w = WSDL::Generator->new($init);
  13. XmlData->getData("CITY");
  14. print $w->get("XmlData");
复制代码
问题总结:
hash 'target_namesp' 和 'location' 和错误,
     'location'指向wsdl文件的url,
     'target_namesp'为代理类路径.

遗留问题:
     不能生成wsdl2.0文档.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP