When using the WCF Service, svcutil is usually used to generate the proxy class and configuration, and the service can be called with the generated default configuration. Let's take a look at the generated default configuration content:
View code
< Client >
< Endpoint Address = "Http: // localhost: 8732/confignameservice/service1 /"
Binding = "Wshttpbinding" Bindingconfiguration = "Wshttpbinding_iservice1"
Contract = "Iservice1" Name = "Wshttpbinding_iservice1" >
< Identity >
< DNS Value = "Localhost" />
</ Identity >
</ Endpoint >
</ Client >
Contract refers to the interface or contract class in the proxy class. If contract is defined as follows, It is the name of the Contract interface by default.
View code
1 [System. servicemodel. servicecontract]
2 Public Interface Iservice1
3 {
4 }
However, if multiple services exist or you need to use namespaces to mark contract, you need to modify the name of contract in the endpoint in the client configuration to include the namespace, for example, as follows:
Contract = "confignameservice. iservice1 ".
Generally, the system finds the interface in the proxy class according to the type name, but this is not the case.CodeThe system will prompt that the default endpoint cannot be found.
View code
1 Using ( VaR Client = New Service1client ())
2 {
3 Console. writeline (client. getdata ( 1 ));
4 }
Change the value of contract back to "iservice1.
The reason is that the configurationname set during the contract definition in the proxy class determines the value to be configured during configuration. This attribute is easily ignored, especially the proxy class generated through svcutil. For example, the following code:
View code
1 [System. servicemodel. servicecontractattribute (configurationname = " Iservice1 " )]
2 Public Interface Iservice1
3 {
4
5 [System. servicemodel. operationcontractattribute (Action = " Http://tempuri.org/IService1/GetData " , Replyaction = " Http://tempuri.org/IService1/GetDataResponse " )]
6 String Getdata ( Int Value );
7
8 [System. servicemodel. operationcontractattribute (Action = " Http://tempuri.org/IService1/GetDataUsingDataContract " , Replyaction = " Http://tempuri.org/IService1/GetDataUsingDataContractResponse " )]
9 Confignameservice. compositetype getdatausingdatacontract (confignameservice. compositetype composite );
10 }
The configurationname is the name of the original service interface. Therefore, you must manually change the configurationname to the required value. Here, you can only change the configurationname defined by the interface in the customer proxy class. Then, the contract value when configuring the endpoint must be consistent with the configurationname value.