java - WSDL 端口的详细信息

标签 java web-services wsdl

我在学习WSDL using online documentation ,对于 WSDL Ports 提到:

A port MUST NOT specify more than one address.

A port MUST NOT specify any binding information other than address information.

给出的例子是:

<portType name="StockQuotePortType">
  <operation name="GetLastTradePrice">
    <input message="tns:GetLastTradePriceInput"/>
    <output message="tns:GetLastTradePriceOutput"/>
  </operation>
</portType>

这个例子中的地址是什么? A port MUST NOT specify any binding information except address information. 这也意味着什么?请帮助我理解这些概念。

最佳答案

我认为您引用了错误的示例,它是在谈论服务标签下的端口。像这样,

<wsdl:service name="StockQuote">
<wsdl:port name="StockQuoteSoap" binding="tns:StockQuoteSoap">
  <soap:address location="http://www.webservicex.net/stockquote.asmx" />
</wsdl:port>
<wsdl:port name="StockQuoteSoap12" binding="tns:StockQuoteSoap12">
  <soap12:address location="http://www.webservicex.net/stockquote.asmx" />
</wsdl:port>
<wsdl:port name="StockQuoteHttpGet" binding="tns:StockQuoteHttpGet">
  <http:address location="http://www.webservicex.net/stockquote.asmx" />
</wsdl:port>
<wsdl:port name="StockQuoteHttpPost" binding="tns:StockQuoteHttpPost">
  <http:address location="http://www.webservicex.net/stockquote.asmx" />
</wsdl:port>

在这里你可以看到这个特定网络服务的地址位置,即

http://www.webservicex.net/stockquote.asmx

这意味着每次您都将在特定绑定(bind)下将您的请求消息发送到该地址位置。

有 4 个端口,或者您可以说 1 个 Web 服务,即 StockQuote,但您可以根据绑定(bind)以 4 种不同的方式调用它。

绑定(bind)定义了每个端口的消息格式和协议(protocol)细节。例如。

<wsdl:binding name="StockQuoteSoap" type="tns:StockQuoteSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetQuote">
  <soap:operation soapAction="http://www.webserviceX.NET/GetQuote" style="document" />
  <wsdl:input>
    <soap:body use="literal" />
  </wsdl:input>
  <wsdl:output>
    <soap:body use="literal" />
  </wsdl:output>
</wsdl:operation>

假设您正在使用“StockQuoteSoap”端口调用 StockQuote 网络服务。因此,在发送您的请求时,您将使用端口标记中提到的上述绑定(bind)。

<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />

http 传输协议(protocol)和 soap 消息传递协议(protocol)。

<wsdl:binding name="StockQuoteSoap" type="tns:StockQuoteSoap">

tns:StockQuoteSoap 指的是您的端口类型

<wsdl:operation name="GetQuote">

GetQuote 是您的操作名称。

这是更关心的,你的webservice是如何在服务器端实现这个绑定(bind)的。 在传统的编程语言中,您可以将操作名称视为方法名称,将端口类型视为类名称。

完整的端口类型定义可以在 wsdl 中看到

<wsdl:portType name="StockQuoteSoap">
<wsdl:operation name="GetQuote">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get Stock quote  for a company Symbol</wsdl:documentation>
  <wsdl:input message="tns:GetQuoteSoapIn" />
  <wsdl:output message="tns:GetQuoteSoapOut" />
</wsdl:operation>

这意味着 StockQuoteSoap 类的 GetQuote 方法将在服务器上针对定义中给定的输入和输出消息执行。

  soap:operation soapAction="http://www.webserviceX.NET/GetQuote" style="document" /> 
  <wsdl:input>
    <soap:body use="literal" />
  </wsdl:input>
  <wsdl:output>
    <soap:body use="literal" />
  </wsdl:output

您的绑定(bind)还指定了输入和输出消息的格式和样式

SOAP Action 是可选功能,服务器使用它来过滤传入的请求。

(3) If I am developing a service in Java programming then we have classes defined in Java package, so where the package structure go in this WSDL? 

让我们举个例子,你想在 url "http://testhost:9999/ws/helloexample" in java in package examplePackage.

您有一个名为 sayHello 的类或接口(interface),您在其中定义了一个方法 public String helloWorld (String Name)。

您正在使用

发布此类
Endpoint.publish("http://testhost:9899/ws/helloexample", new sayHello());

因此您生成的 wsdl 将像下面这样映射。

  Interface or class name: PortType 
  Method name: Operation
  Method name: input message  (request)
  Method name+Response: output message (response)

<portType name="sayHello">
    <operation name="helloWorld">
       <input message="tns:helloWorld"/>
       <output message="tns:helloWorldResponse"/>
    </operation>
</portType>

   Endpoint.publish("http://testhost:9899/ws/helloexample",new sayHello())
   : address location

  <wsdl:service name="sayHelloService">
  <wsdl:port name="sayHelloPort" binding="tns:sayHelloPortBinding">
  <soap:address location="http://testhost:9899/ws/helloexample" />
  </wsdl:port>

您可以使用各种可用的 Web 服务注释,如 @WebParam、@WebMethod、@WebResult 等来更改 wsdl 中的操作名称、消息部分名称、命名空间等。

在生成的 wsdl 中进一步添加绑定(bind),

<wsdl:binding name="sayHelloPortBinding" type="tns:sayHello">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="helloWorld">
<soap:operation soapAction="" style="rpc"/>
<wsdl:input>
<soap:body use="literal" namespace="http://examplePackage" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" namespace="http://examplePackage" />
</wsdl:output>
</wsdl:operation>

SOAPAction 可以在@WebMethod 注解中设置。样式可以在@SOAPBinding 中设置。

关于java - WSDL 端口的详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20891198/

相关文章:

c# - 使用 SOAP Web 引用将 C# 类编译为 .dll 错误 CS0234

.net - 如何将单个 WCF 服务配置为具有多个 HTTP 和 HTTPS 端点?

python - wsdl 文件解析结果为 'Unable to resolve type {http://schemas.xmlsoap.org/soap/encoding/}Array.'

php - WSDL SoapClient 和 PHP + 自己的命名空间

java - Android View 需要 API 级别 14

java.lang.UnsupportedOperationException : Not supported yet

java - 无法在 tomcat 上访问 webservice 出现 500 错误

java - 按主键删除具有复合键的实体

java.lang.IndexOutOfBoundsException : Index: 264

iphone - sudzc 还是 wsdl2obj?