[ITOO] WCF -- the Client calls the WCF Service, and the itooclient calls the wcf
The three steps have already taken two steps. After a WCF Service is released, it waits for the user to call it. It only provides one interface, exposing the address and contract, do not expose how the service is implemented. Next, let's talk about how the client calls the WCF Service.
In fact, it is very easy to call. First, let us identify the services we need, that is, configure the same endpoint information, add a service reference, and finally call the corresponding method.
As shown in the configuration file:
<applicationSettings> <WebDemoClient.Properties.Settings> <setting name="WebDemoClient_WebHelloService_WebHello" serializeAs="String"> <value>http://192.168.24.94:82/WebHello.asmx</value> </setting> <setting name="WebDemoClient_WebAdd_WebHello" serializeAs="String"> <value>http://192.168.24.94:82/WebHello.asmx</value> </setting> </WebDemoClient.Properties.Settings> </applicationSettings>
Then call the method:
Protected void Button1_Click (object sender, EventArgs e) {WebHelloService. WebHello web = newWebHelloService. WebHello (); this. TextBox1. Text = web. Hello (" ");}
The final running result is successful:
The client can call many services that we need to implement our functions at the same time, but when we need to do one thing at the same time many services or many methods in one service, in this case, transactions are involved. To ensure data consistency and atomicity, distributed transactions are supported in WCF. That is to say, transactions can exist between multiple services and clients across the boundaries of services, processes, and machines. WCF provides protocols that support distributed transactions and related features.
At the same time, WCF has many benefits. I also mentioned it in the first WCF introduction. In this way, the use of a complete WCF Service is finished. It also fully proves that our dream will be realized as long as we follow the correct path. We can call different existing interfaces to serve us and learn to use the power of others, standing on the shoulders of giants. Service-oriented era, interface-oriented programming.