Each WCF Service is related to the address, binding, and contract, while WCF associates ABC with each other through the endpoint. Every
The endpoint must be in three aspects: ABC.
The process provides an endpoint
For the client to call. Each
Each endpoint corresponds to a unique address, but multiple
The endpoint can share the same binding and contract, and each service can provide multiple endpoints for the client to cancel.
Use the configuration file
Reflect Microsoft again
. The only thing worth noting is that the behaviorconfiguration attribute is added to the service node.
<? XML version = "1.0" ?>
< Configuration Xmlns = "Http://schemas.microsoft.com/.NetConfiguration/v2.0" >
< System . Servicemodel >
< Services >
<! -- <Service name = "myservice" behaviorconfiguration = "returnfaults">
<Endpoint contract = "imyservice" binding = "wshttpbinding"/>
</Service> -->
< Service Name = "Anrs. Service. anrsservice" Behaviorconfiguration = "Returnfaults" >
< Endpoint Contract = "Anrs. Service. ianrsservicecontract1"
Binding = "Wshttpbinding"
Address = "Http: // localhost: 4021/anrsservicebyiis/anrsservice /" />
</ Service >
</ Services >
< Behaviors >
< Servicebehaviors >
< Behavior Name = "Returnfaults" >
< Servicemetadata Httpgetenabled = "True" > </ Servicemetadata >
< Servicedebug Includeexceptiondetailinfaults = "True" />
</ Behavior >
</ Servicebehaviors >
</ Behaviors >
</ System. servicemodel >
<System. Web>
<CompilationDebug= "True"/>
</System. Web>
</Configuration>
The benefits of using the configuration file are self-explanatory. No matter the service address, binding, or contract has been modified, you do not need to re-compile or deploy the service. After the configuration is complete, you can see the following picture in the browser.
Programming Control endpoint
Compared with the configuration file, the Programming Control endpoint does not have a few linesCode. The following code is equivalent to the configuration document above.
Using System;
Using System. servicemodel;
Using System. servicemodel. channels;
Namespace Anrs. Service
{
Class Program
{
Static Void Main ( String [] ARGs)
{
Servicehost sh = New Servicehost ( Typeof (Anrsservice ));
Binding wshttpbinding = New Wshttpbinding ();
Sh. addserviceendpoint ( Typeof (Ianrsservicecontract1 ),
Wshttpbinding,
New Uri ( " HTTP: /localhost: 8086/anrsservice/ " ));
Sh. open ();
Console. Write ( " Press any key to exit " );
Console. Readline ();
Sh. Close ();
}
}
}