在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
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
To add a WCF endpoint that is compatible with ASP.NET Web service clients in a configuration file
ExampleThe 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#
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
> <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 |
请发表评论