问题
I am learning WSDL using online documentation, for WSDL
Ports
it is mentioned that:
A port MUST NOT specify more than one address.
A port MUST NOT specify any binding information other than address information.
and the example given is:
<portType name="StockQuotePortType">
<operation name="GetLastTradePrice">
<input message="tns:GetLastTradePriceInput"/>
<output message="tns:GetLastTradePriceOutput"/>
</operation>
</portType>
What is address in this example? also what it means that A port MUST NOT specify any binding information other than address information.
? Please help me in understanding the concepts.
回答1:
I think you have referred wrong example, It was talking about port under service tag. Something like this,
<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>
Here you can see address location of this particular webservice i.e.
http://www.webservicex.net/stockquote.asmx
That means each time, you will send your request message on this address location under a specific binding.
There are 4 ports or you can say 1 webservices i.e. StockQuote but you can call it in 4 different ways as per bindings.
Bindings defines message format and protocol details for each port. For example.
<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>
Lets say you are calling StockQuote webservice using "StockQuoteSoap" port. So while sending your request you will use above binding as referred in port tag.
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
http transport protocol and soap messaging protocol.
<wsdl:binding name="StockQuoteSoap" type="tns:StockQuoteSoap">
tns:StockQuoteSoap is referring at your port type
<wsdl:operation name="GetQuote">
GetQuote is your operation name.
This is more concerned, how your webservice is implemented on server side for this binding. You can consider operation name as method name and port type as class name in traditional programming language.
Full port type difinition can be seen in wsdl as
<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>
That means GetQuote method of StockQuoteSoap class will be executed at server for given input and output message in definition.
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
your binding also specifies input and output message format and style
SOAP Action is optional feature which is used by server to filter out incoming request.
(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?
Lets take an example where, you want to publish a webservice at
url "http://testhost:9999/ws/helloexample"
in java in package examplePackage.
You have a class or interface named sayHello in which you have defined a method public String helloWorld (String Name).
You are publishing this class using
Endpoint.publish("http://testhost:9899/ws/helloexample", new sayHello());
So your generated wsdl will be mapped like below.
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>
You can use various webservice annotations available like @WebParam, @WebMethod, @WebResult etc to change operation name, message part name, namespace etc in wsdl.
Further addidng binding in generated 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>
SOAPAction can be set in @WebMethod annotation. style can be set in @SOAPBinding anootation.
来源:https://stackoverflow.com/questions/20891198/details-on-wsdl-ports