How to: Configure WCF Service to interoperate with ASP. NET web service clients

Source: Internet
Author: User

To configure a Windows Communication Foundation (WCF) service endpoint to be interoperable with ASP. NET web service clients, use the system. servicemodel. basichttpbinding type as the binding type for your service endpoint.

You can optionally enable support for HTTPS and transport-level client authentication on the binding. ASP. net web service clients do not support MTOM message encoding, so the system. servicemodel. basichttpbinding. messageencoding property shocould be left as its default value, which is system. servicemodel. wsmessageencoding. text. ASP. net web service clients do not support WS-Security, so the system. servicemodel. basichttpbinding. security shoshould be set to transport.

To make the metadata for a WCF Service available to ASP. NET Web Service proxy generation tools (that is, Web Services Description Language tool (wsdl.exe), Web services discovery tool (disco.exe), and the Add web reference feature in Visual Studio ), you shoshould expose an HTTP/get metadata endpoint.

To add a WCF endpoint that is compatible with ASP. NET web service clients in code
    1. Create a newBasichttpbindingInstance

    2. Optionally enable transport security for this service endpoint binding by setting the security mode for the bindingTransport. For details, please see transport security.

    3. Add a new application endpoint to your service host using the binding instance that you just created. for details about how to add a service endpoint in code, see the how to: create a service endpoint in code.

    4. Enable an HTTP/get metadata endpoint for your service. For details see How to: publish metadata for a service using code.

To add a WCF endpoint that is compatible with ASP. NET web service clients in a configuration file
    1. Create a newBasichttpbindingBinding configuration. For details, see the how to: specify a Service binding in configuration.

    2. Optionally enable transport security for this service endpoint binding configuration by setting the security mode for the bindingTransport. For details, see transport security.

    3. Configure a new application endpoint for your service using the binding configuration that you just created. for details about how to add a service endpoint in a configuration file, see the how to: create a service endpoint in configuration.

    4. Enable an HTTP/get metadata endpoint for your service. For details see the how to: publish metadata for a service using a configuration file.

Example

The following example code demonstrates how to add a WCF endpoint that is compatible with ASP. NET web service clients in code and alternatively in configuration files.

C # copy code
 Using System; Using System. Collections. Generic; Using System. text; Using System. servicemodel; Using System. servicemodel. description; [servicecontract] Public Interface iecho {[operationcontract] String Echo ( String S );} Public  Class Myservice: iecho { Public   String Echo ( String S ){ Return S ;}} Class Program { Static   Void Main ( String [] ARGs ){ String Baseaddress = "Http:// Localhost: 8080/wcfselfhost /"; Servicehost host = New Servicehost (typeof (myservice ),New Uri (baseaddress )); // Create a basichttpbinding instance Basichttpbinding binding = New Basichttpbinding (); // Add a service endpoint using the created binding Host. addserviceendpoint (typeof (iecho), binding, "Echo1" ); Host. open (); console. writeline ( "Service Listening on {0 }..." , Baseaddress); console. Readline (); host. Close ();}}
XML copy code
 <  Configuration  >  < System. servicemodel  >  <  Services  >  <  Service Name = "myservice" behaviorconfiguration = "httpgetmetadata" >  <  Endpoint Address = "echo2" Contract = "iecho" binding = "basichttpbinding" />  </  Service  >  </ Services  >  <  Behaviors  >  <  Servicebehaviors  >  <  Behavior Name = "httpgetmetadata" >  <  Servicemetadata Httpgetenabled = "true" />  </  Behavior  > </  Servicebehaviors  >  </  Behaviors  >  </  System. servicemodel  >  </  Configuration  > 
 
 
 
Ref: How to: Configure WCF Service to interoperate with ASP. NET web service clients
Related Article

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.