gpt4 book ai didi

java - WSDL 或 wsimport 和 wsdl (mono) 严重损坏

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:59:01 26 4
gpt4 key购买 nike

编辑 我从下面给出的例子开始,但我现在有:

  • 尝试了 W3C 规范中的示例。修复另一个错误后(绑定(bind)在一个地方被称为 StockQuoteSoapBinding,在另一个地方被称为 StockQuoteBinding),它给出了同样的问题。
  • 尝试了单声道生成器 wsdl 以查看是否是 wsimport 造成的。它给出了一个等效的错误。

所以在我看来,尽管对 SOAP 大肆宣传,但它实际上并没有用——至少不像宣传的那样。我不敢相信没有人通过这些生成器运行最容易找到的 wsdl 示例。

原始问题

wsimport 在以下 wsdl 上失败:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="OrdersService"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:os="http://example/schema/OrdersService"
xmlns:tns="http://example/ns/OrdersService"
targetNamespace="http://example/ns/OrdersService"
>

<wsdl:types>
<xsd:schema
targetNamespace="http://example/schema/OrdersService">

<xsd:element name="o:GetOrders">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="criteria" type="string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="os:GetOrdersResponse">
<xsd:complexType>
<xsd:all>
<xsd:element name="orders" type="string"/>
</xsd:all>
</xsd:complexType>
</xsd:element>

</xsd:schema>
</wsdl:types>

<wsdl:message name="GetOrdersRequest">
<wsdl:part name="parameters" element="os:GetOrders"/>
</wsdl:message>

<wsdl:message name="GetOrdersResponse">
<wsdl:part name="parameters" element="os:GetOrdersResponse"/>
</wsdl:message>

<wsdl:portType name="GetOrdersPortType">
<wsdl:operation name="GetOrders">
<wsdl:input message="tns:GetOrdersRequest"/>
<wsdl:output message="tns:GetOrdersResponse"/>
</wsdl:operation>
</wsdl:portType>

<wsdl:binding name="GetOrdersBinding" type="tns:GetOrdersPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetOrders">
<soap:operation soapAction=""/>
<wsdl:input><soap:body use="literal"/></wsdl:input>
<wsdl:output><soap:body use="literal"/></wsdl:output>
</wsdl:operation>
</wsdl:binding>

<wsdl:service name="OrdersService">
<wsdl:port name="GetOrdersPort" binding="tns:GetOrdersBinding">
<soap:address location="http://localhost:8080/svc/OrdersService/GetOrders"/>
</wsdl:port>
</wsdl:service>

</wsdl:definitions>

与:

parsing WSDL...


[ERROR] Schema descriptor {http://example/schema/OrdersService}GetOrders in message part "parameters" is not defined and could not be bound to Java. Perhaps the schema descriptor {http://example/schema/OrdersService}GetOrders is not defined in the schema imported/included in the WSDL. You can either add such imports/includes or run wsimport and provide the schema location using -b switch.
line 35 of file:test.wsdl

最佳答案

虽然问题很老,但这里有一个有效的 WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="OrdersService"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:os="http://example/schema/OrdersService"
xmlns:tns="http://example/ns/OrdersService"
targetNamespace="http://example/ns/OrdersService">

<wsdl:types>
<xsd:schema targetNamespace="http://example/schema/OrdersService">

<xsd:element name="GetOrders">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="criteria" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="GetOrdersResponse">
<xsd:complexType>
<xsd:all>
<xsd:element name="orders" type="xsd:string" />
</xsd:all>
</xsd:complexType>
</xsd:element>

</xsd:schema>
</wsdl:types>

<wsdl:message name="GetOrdersRequest">
<wsdl:part name="parameters" element="os:GetOrders" />
</wsdl:message>

<wsdl:message name="GetOrdersResponse">
<wsdl:part name="parameters" element="os:GetOrdersResponse" />
</wsdl:message>

<wsdl:portType name="GetOrdersPortType">
<wsdl:operation name="GetOrders">
<wsdl:input message="tns:GetOrdersRequest" />
<wsdl:output message="tns:GetOrdersResponse" />
</wsdl:operation>
</wsdl:portType>

<wsdl:binding name="GetOrdersBinding" type="tns:GetOrdersPortType">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetOrders">
<soap:operation soapAction="" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>

<wsdl:service name="OrdersService">
<wsdl:port name="GetOrdersPort" binding="tns:GetOrdersBinding">
<soap:address
location="http://localhost:8080/svc/OrdersService/GetOrders" />
</wsdl:port>
</wsdl:service>

</wsdl:definitions>

我改变的事情:

  • xmlns:xsd 设置为 http://www.w3.org/2001/XMLSchema 而不是 http://www.w3 .org/1999/XMLSchema(1999版本已经很过时了)

  • 从模式元素中删除了命名空间(GetOrders 而不是 o:GetOrdersGetOrdersResponse 而不是 os: GetOrdersResponse)(在元素或类型定义的 name 属性中不允许使用命名空间限定符)

  • 为子元素 criteriaorders 使用了正确的类型:xsd:string 而不是 string


我同意,WSDL 一开始可能会很困难,但是,一旦您掌握了它,没有什么比定义明确的接口(interface)更好的了。如果我可以选择,我会毫不犹豫地选择 wsdl 而不是 json-REST-API。但我想这是一个品味问题 ;-)

关于java - WSDL 或 wsimport 和 wsdl (mono) 严重损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1682479/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com