有关WSDL端口的详细信息

时间:2014-01-02 20:24:17

标签: java web-services wsdl

我正在学习WSDL using online documentationWSDL Ports提到:

  

端口不得指定多个地址。

     

端口不得指定除地址之外的任何绑定信息   信息。

,给出的例子是:

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

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

1 个答案:

答案 0 :(得分:3)

我认为你提到了错误的例子,它正在谈论服务标签下的端口。像这样的东西,

<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

这意味着每次您都会在特定绑定下的此地址位置发送您的请求消息。

有4个端口,或者你可以说1个网络服务,即StockQuote,但你可以按照绑定以4种不同的方式调用它。

绑定定义了每个端口的消息格式和协议详细信息。例如。

<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 Web服务。因此,在发送您的请求时,您将使用端口标记中引用的上述绑定。

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

http传输协议和soap消息传递协议。

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

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

<wsdl:operation name="GetQuote">

GetQuote是您的操作名称。

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

在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

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

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? 

让我们举一个例子,你想在哪里发布一个web服务 java in package examplePackage中的url "http://testhost:9999/ws/helloexample"

您有一个名为sayHello的类或接口,您在其中定义了一个方法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中进一步添加绑定,

<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>

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