15 days proficient in WCF-how does the client know the list of functions provided by the server on the third day, wcfclient

Source: Internet
Author: User

15 days proficient in WCF-how does the client know the list of functions provided by the server on the third day, wcfclient

When we go to health care, we usually ask the girl what services and prices can be provided here. At this time, the girl may dictate some services or provide a service list.

In the same way in wcf, only the client can understand what functions the service can provide, the client can perform operations based on the functions provided by the server.

The question is, how does the service provide the function to the client for selection ??? This is the web service description language )...

 

I. wsdl

Now that you know, the wsdl is the list provided by the server to the client. The following question comes. How is server provided ??? If you are more careful, you may know that

The endpoint mentioned in this article is as follows.

In the figure above, you can see that Homeservice provides two endpoints, one is "service endpoint" and the other is "metadata endpoint ". And you can see that the metadata endpoint is

Http: // 192.168.16.16: 19200/mex. When the client accesses this address through svcutil, it obtains the list of functions provided by the server, and then the client can generate

A proxy file, and then, you know, a variety of hacker, XXXClient.

 

2. seeing is real

1. Witness the wsdl

To see the wsdl, you only need to open the service address through http: // localhost: 19200, such:

 

Then, click: http: // localhost: 19200 /? SingleWsdl

 

Now you can see the server function list, which is too heavy-weight by tmd. It has completely become a reality in the world. Let's analyze it in detail in the next section.

 

2. Witness the XXXclient of the client

As I mentioned earlier, when you use vs for "service reference", svcutil will view the wsdl based on the http: // localhost: 19200/mex address and then generate a proxy, let's take a look at it.

 

 

Click "OK". A Reference. cs file is generated under the Service References folder.

 

Then we open Reference. cs and we can see a HomeServiceClient inherited from ClientBase.

 

 

Iii. Detailed analysis of the wsdl File

To learn about wcf, you must be able to understand wsdl like svcutil.

 

1. First, check that the server provides an Update operation. The parameter is an id, a Student, a custom complex type, and the returned result is also Student.

Complex type.

1 namespace MyService2 {3     [ServiceContract]4     public interface IHomeService5     {6         [OperationContract]7         Student Update(int id, Student stu);8     }9 }

 

2. You have seen the xml file wsdl just now. Let's look at the nodes one by one.

<1> portType and operation nodes

After you see the following, I think you can guess it. portType is the contract (IHomeService), and operation is the contract method (Update ).

Now you see an input and an output. This is the so-called "input message" and "output Message". What does that mean ??? That is to say, the message sent from the client to the server is called "input message ".

The client is called "Output Message". Here you should understand that the Update method in C # contains input and output parameters, however, the ing to wsdl contains two messages: input and output, which are classic messages.

"Request-response" mode.

 

Now, let's continue. In wsdl: input and wsdl: output, there is an Action attribute, which is very interesting. The underlying layer of wcf is to find the corresponding method through this address, for example, the proxy we see

The above section of the Update method in the class.

 

<2> message and types nodes

If you continue, you will find that there is a message attribute in the input and output, corresponding to IHomeService_Update_InputMessage and IHomeService_Update_OutputMessage,

This is exactly the reference of the message node, for example:

In this figure, you can see that both input and output have A wsdl: part node, which indicates the parameters to be carried in the input and output, such as element = "tns: Update ", it is referenced.

Name = Update node in element, for example:

 

Now, let's take another screenshot. We can see that the transmission protocol is soap, the service address, and so on... Then there is nothing to say.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.