Use WCF to reference the IIS-based boarding service. use wcf to reference the iis-based boarding service.
Boarding services through IIS
In the previous example, the console is used as the boarding mode of WCF, or the reference of the Contract Project is directly added, and service objects are created through configuration or ChannelFactory, in fact, it is also common to create WCF in the form of IIS in most development scenarios.
Each Webservice has an asmx text file, and the client can call Webservice by accessing the. asmx file. Of course, similar to Webservice, each WCF Service has a corresponding. svc text file. All the WCF services based on the requirements of the IIS service are provided accordingly. svc file ,. the svc file is deployed in the IIS site, and the call to the WCF Service is now correct. access the svc file .. The svc file only contains commands such as % @ ServiceHost, which has a mandatory Service attribute and optional attribute. The following code shows the content of a simple. svc text.
The Service attribute is specified as a fully-qualified WCF Service class.
The WCF Service hosted in IIS is actually a WEB application. put the svc file on the Web and use the web. config file to configure the endpoint of WCF and ServiceMetadataBehavior Service Behavior for publishing metadata. Because the service is called by accessing the service. implemented by the svc file. the address of the svc file is the service (endpoint) address for the client. Therefore, you do not need to configure the endpoint adder. The configuration code is as follows:
Except that no address is specified for the endpoint, ServiceMetadataBehavior is used to publish metadata without specifying the publishing address of the element. In this case, add? The wsdl query string is the metadata publishing address. In the current example, after the service is successfully hosted on a local Web application, you can use http: // 127.0.0.1: 1111/website name/CalculatorService. svc? Wdsl obtains the WSDL file indicating the service metadata, which is why a long xml content is returned when we right-click the. svc file.
Modify the client again:
Only the address attribute is modified. Assume that our Web application is called MyWeb. In this case, we can find the published. svc file.
So far, we have introduced two types of WCF methods:
One is to host the WCF Service in the console program:
1. Add a service reference (based on the metadata address), create a Client object, and then perform operations;
2. Add a reference to the contract project, and then create a Channel object (through the contract type, Binding, and an address) through ChannelFactory );
3. add a reference to the contract project, and then create a Channel object through ChannelFactory (the endpoint information is configured in config, and then created using the endpoint name as the ChannelFactory parameter ).
One is to use IIS as the host:
1. Add a reference to the contract project, and then modify the endpoint address of the configuration file to the address of. svc. In this way, create a proxy object using ChannelFactory;
2. Add a reference to the contract project, and then create a Channel object (through the contract type, Binding, and an address, the address at this time should be. svc) through ChannelFactory ).