[WCF] endpoint

Source: Internet
Author: User

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 ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.