How to: Configure WCF Service to Interoperate with ASP.NET Web Service Clients

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 should 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 should 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 should 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 new BasicHttpBinding instance

  2. Optionally enable transport security for this service endpoint binding by setting the security mode for the binding to Transport. 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 new BasicHttpBinding binding 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 binding to Transport. 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.

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

转载于:https://www.cnblogs.com/javafun/archive/2008/01/09/1031552.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值