• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Howto:ConfigureWCFServicetoInteroperatewithASP.NETWebServiceClients

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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 Transport.

To make the metadata for a WCF service available to ASP.NET Web service proxy generation tools (that is, 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();
}
}
>
<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

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Asp.Net的基于Forms的验证机制--角色授权发布时间:2022-07-10
下一篇:
asp.net core模块学习发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap