Original: 15 days proficient wcf--The third day how the client knows the list of features provided by the server
Usually when we go to the big health care, will find a girl to ask what service here, what price, this time may the girl will dictate some services or provide a list of services, so the big
Home can do without bullying, such a living example, in WCF is also a truth, only the client understand the service can provide what functions, the client can be based on the functions provided by the server
Consumption, that question came, service how to provide the function of the client to choose it??? This is the WSDL I want to talk about (Web Service Description Language) ...
One: WSDL
Now that you know that the WSDL is the server's manifest to the client, the following question comes up. How is the server provided??? If you are more careful, you may know that I
One of the endpoint mentioned in this article is as follows.
In the above picture, you can see that Homeservice provides two endpoints, one is "service endpoint" and one is "metadata endpoint". And as you can see, the endpoint address of the meta-data is
Http://192.168.16.16:19200/mex, when the client accesses the address through svcutil, it gets the list of features that the server can provide, and then the client can generate a
A proxy file, and then, you know, all kinds of popping, xxxclient.
Second: Seeing is believing
1. Witness the WSDL
To see the WSDL, you only need to open the service address via http://localhost:19200, such as:
Then click: http://localhost:19200/?singleWsdl
Now what you see is the server function list, too TMD heavyweight, has completely fruit body in the world before, the next section of our detailed analysis.
2. Witness the xxxclient on the client side
As I said earlier, when you use VS as a "service reference", Svcutil will look at the WSDL based on the Http://localhost:19200/mex address and then generate the proxy, which we'll look at in detail below.
After clicking OK, we can see that a Reference.cs file is generated under the Service References folder.
Then we open the Reference.cs and we can see a homeserviceclient that inherits from ClientBase.
III: Detailed analysis of WSDL files
To learn WCF, you must be able to read WSDL like svcutil.
1. First look at the server provides an update operation, the parameter is an ID, a student this custom complex type, and return is also student this
Complex type.
1 namespace MyService 2 {3 [ServiceContract]4public interface Ihomeservice5 {6 [OperationContract]7 Student Update (int ID, Student stu); 8 }9 }
2. wsdl This XML file, just as you saw, below we have a node to see
<1> PortType and Operation nodes
When you see the following, I think you can guess, porttype is the contract (Ihomeservice), operation is the contract method (Update), but a bit of meaning, in the operation
Below you see a input, an output, this is the so-called "input message", "output message", what does that mean??? That is, the client-to-server message is called an "input message", and the server
Client side is called "Output message", here you should seem to understand, my C # Update method is the input and the parameter, but this mapping into the WSDL is two messages, input and output, this is the classic
"Request-response" mode.
OK, keep looking down, there is an action property in Wsdl:input and Wsdl:output, which is interesting, and the bottom of WCF is to find the corresponding method by this address, such as the proxy we see
There is a section on the Update method in the class.
<2> message and Types nodes
If you keep looking down, you will find that there is also a message property in input and output, corresponding to Ihomeservice_update_inputmessage and Ihomeservice_update_outputmessage,
This happens to be a reference to the message node, such as:
From this diagram, you can see that both input and output have a Wsdl:part node, which indicates the parameters that need to be carried in input and output, such as element= "Tns:update", which references the
The Name=update node in element, such as:
Well, finally I cut a diagram, you can see that the transport protocol for SOAP, service address and so on ... And then there's nothing left to say.
15 days proficient wcf--The third day how the client knows the list of features provided by the server