【问题标题】:Using Java Webservice in .NET在 .NET 中使用 Java Web 服务
【发布时间】:2009-09-28 11:48:23
【问题描述】:

我正在将一个 .NET 应用程序与一个名为 Hermes2 (H2O) 的基于 Servlet 的 Java 应用程序集成在一起。 Java 应用程序公开了几个 Web 服务,我正在尝试在 Visual Studio 2008 中创建对这些服务的 Web 引用。但是这只会导致空代理,并用错误消息注释:“CODEGEN:来自命名空间的操作绑定'请求'' http://service.ebms.edi.cecid.hku.hk/' 被忽略。不支持为 use=literal 消息指定类型。"。

当我尝试通过 .NET 中的 wsdl.exe 实用程序运行 WSDL 时,我得到以下输出:

Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Warning: This web reference does not conform to WS-I Basic Profile v1.1.
R2204: A document-literal binding in a DESCRIPTION MUST refer, in each of its soapbind:body element(s), only to wsdl:part element(s) that have been defined using the element attribute. 
-  Part 'messageId' of message 'EbmsRequestMsg' from service description with targetNamespace='http://service.ebms.edi.cecid.hku.hk/'.
-  Part 'hasMessage' of message 'EbmsResponseMsg' from service description with targetNamespace='http://service.ebms.edi.cecid.hku.hk/'.

For more details on the WS-I Basic Profile v1.1, see the specification 
at http://www.ws-i.org/Profiles/BasicProfile-1.1.html.

Warning: one or more operations were skipped.
Warnings were encountered. Review generated source comments for more details.

Writing file 'C:\Files\Temp\Helsekortet\Hermes\wsdl\EbmsMessageReceiverDownload.cs'.

有谁知道问题出在哪里,以及如何解决?我会假设 Hermes2 使用某种常见的 Web 服务库。是否有任何这样的 Java 库会产生无效的 WSDL,或者这只是 .NET 不支持的某些功能?

WSDL 如下(我在这里看不到任何附加文件的方式,而且我没有指向 WSDL 的 URL。抱歉发布了一个臃肿的问题):

<?xml version="1.0" encoding="utf-8"?> 
<definitions 
 xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
 xmlns:s="http://www.w3.org/2001/XMLSchema" 
 xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
 xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" 
 xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" 
 xmlns="http://schemas.xmlsoap.org/wsdl/"
 xmlns:p="http://service.ebms.edi.cecid.hku.hk/" 
 targetNamespace="http://service.ebms.edi.cecid.hku.hk/">
<types>
</types>
<message name="EbmsRequestMsg">
  <part name="messageId" type="s:string" /> 
</message>
<message name="EbmsResponseMsg">
  <part name="hasMessage" type="s:string" /> 
</message>
<portType name="EbmsReceiverDownload">
  <operation name="Request">
    <input message="p:EbmsRequestMsg" /> 
    <output message="p:EbmsResponseMsg" /> 
  </operation>
</portType>
<binding name="EbmsSoapHttpReceiverDownload" type="p:EbmsReceiverDownload">
  <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> 
  <operation name="Request">
    <soap:operation soapAction="Ebmsreceiverdownload" style="document" /> 
    <input>
      <soap:body use="literal" /> 
    </input>
    <output>
      <soap:body use="literal" /> 
    </output>
  </operation>
</binding>
<service name="EbmsMessageReceiverDownload">
  <documentation>Documentation not available.</documentation> 
  <port name="EbmsReceiverDownload" binding="p:EbmsSoapHttpReceiverDownload">
    <soap:address location="http://127.0.0.1:8080/corvus/httpd/ebms/receiver" /> 
  </port>
</service>
</definitions>

希望任何人都可以提供帮助。

【问题讨论】:

    标签: java .net web-services wsdl


    【解决方案1】:
    <message name="EbmsRequestMsg">
      <part name="messageId" type="s:string" /> 
    </message>
    <message name="EbmsResponseMsg">
      <part name="hasMessage" type="s:string" /> 
    

    这些必须引用元素声明而不是原始简单类型。您需要创建一个包含字符串简单类型的元素包装器。

    【讨论】:

    • 您知道如何做到这一点吗?我在 WSDL 方面不是很有经验,所以希望您能给我一些建议。另外我认为生成这个 WSDL 的 Java Webservice 库也应该生成这个?
    • 这真的取决于使用哪个 Java 库来实现 web 服务。
    • 是的,确实如此。但是标准就是标准;谁会实现或使用不生成标准 WSDL 的 Web 服务库?
    • 很多人,包括旧库、Axis 1.2 和其他几个用户。很多人不关心标准。
    【解决方案2】:

    我希望有人能提供有关如何解决 Martin 指出的问题的信息,但没有人这样做:-/

    然而,经过几个小时的阅读和尝试,我终于设法将 Java 应用程序生成的 WSDL 重写为符合 .NETs Webservices 实现所遵循的标准。

    这里使用的Java Webservices框架似乎是罪人,但我不知道使用什么库,因为我不熟悉其中的许多。除了不生成符合标准的 WSDL 之外,这个应用程序中的 Web 服务还有其他几个问题,据我所知,这些问题在很久以前就已经解决了。例如,使用 mime“multipart/related”传输二进制数据,但没有对 SOAP xml 中的数据的引用。

    而我认为 .NET 很烂...无论如何,这是重写后生成的 WSDL 类型和消息部分(省略了其他部分,因为这些部分没有被修改):

    <types>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://service.ebms.edi.cecid.hku.hk/" elementFormDefault="qualified">
            <xs:element name="messageId" type="xs:string" />
            <xs:element name="hasMessage" type="xs:string" />
        </xs:schema>
    </types>
    <message name="EbmsRequestMsg">
        <part name="messageId" element="p:messageId" />
    </message>
    <message name="EbmsResponseMsg">
        <part name="hasMessage" element="p:hasMessage" />
    </message>
    

    感谢 Martin 为我指明了正确的方向 :-)

    【讨论】:

      猜你喜欢
      • 2012-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-12
      • 1970-01-01
      相关资源
      最近更新 更多