In WCF, wsHttpBinding configures the instance program, wcfwshttpbinding
WsHttpBinding configuration instance program in WCF
I have been familiar with the WCF technology in the past two days and feel it is necessary to record some issues that have not been clearly identified. In order to facilitate the subsequent investigation and elimination of relevant problems, we also hope to provide some help to those in need.
1 Introduction
This section describes the wsHttpBinding instance used for address binding in a WCF program.
2 Background
In the WCF technology, after the WCF Service is released on the server side, the client connects the server to call the Service interface in the following four ways:
- HTTP: Common http connections are similar to website transmission methods;
- TCP: the TCP protocol is used to achieve the connection between the local network and remote servers, which is more efficient than HTTP and supports security control;
- Name Pipe: Name pipeline technology, used for communication between different processes on the local machine;
- MSMQ: (Microsoft Message Queue, Microsoft Message Queue) is a reliable Message Queuing technology that allows applications to send messages to their destinations through Queue routing.
Figure 1 connection and communication between the WCF Service and the Client [1]
Figure 1 shows how the WCF Service communicates with each Client on the server.
[1] introduced from Beginning Visual C #2010, Chatper 26, page 902.
3 code
Create in Visual Studio 2010.
First, the first example is to use wsHttpBinding and then use the Console application as the Host and Client. Its engineering structure is as follows:
Step 1: Create a WCF Service Library project. WcfSericeLib and VS will automatically generate the interface file IService1.cs and the class implementation file Service1.cs.
Step 2: Create the ConsoleHost and leleclient of the Console Application project respectively.
In the App. config file, we can see the following Configuration:
We can see that wsHttpBinding is used by default, and the program can be compiled and run. However, the purpose of this program is to host the WCF Service to ConsoleHost, enable ConsoleHost, and then call the enabled Service through ConsoleClient.
Step 3: Cut the App. config file in WcfServiceLib to lelehost, and introduce WcfServiceLib. dll in ConsoleHost.
Step 4: add the System. ServiceModel library to ConsoleHost and change the Program. cs file as follows:
In this case, set ConsoleHost as the startup project to successfully start the Service.
Step 5: Run consolehost.exe in the consolehostproject debugdirectory to view the startup information of Service1 Started. Then Add Service Reference in ConsoleClient, copy the baseAddress in App. config in ConsoleHost to the address bar, and you can find the current Service. As shown in:
After the preceding steps are completed, the configuration file of app. config is automatically generated in leleclient. For details, see the code.
Step 6: Change leleclient program. cs as follows:
Finally, run lelehost.exeto start serviceand then run leleclient.exe. the following result is displayed:
This example is complete.
Download the source code of the entire project: WCFDemo_wsHttpBinding.zip
4. Discussion
In this example, only Handle of the Service in the WCF Application Library is sent to the Console. In this case, the lelehost can be a remote server and the guest client can be a client in different regions.
5 Copyright
If the source is indicated, the data can be copied and disseminated freely.
References:
Beginning Visual C #2010
Http://blog.csdn.net/fangxing80/article/details/6106228
6. About the author
Ray Lei is a C ++/C # And mobile platform developer in the accumulation learning stage.