绑定协议名称 支持可靠性 默认可靠性 支持有序传递 默认有序传递 BasicHttpBinding No N/A No N/A NetTcpBinding Yes Off Yes On NetPeerTcpBinding No N/A No N/A NetNamedPipeBinding No N/A (On) Yes N/A (On) WSHttpBinding Yes Off Yes On WSFederationHttpBinding Yes Off Yes On WSDualHttpBinding Yes On Yes On NetMsmqBinding No N/A No N/A MsmqIntegrationBinding No N/A No N/A
首先添加一个wcf应用程序:
using System.ServiceModel; namespace WcfService1 { [ServiceContract] public interface IGeneralCalculator { [OperationContract] double Add(double x, double y); } }
namespace WcfService1 { public class GeneralCalculator : IGeneralCalculator { public double Add(double x, double y) { return x + y; } } }
再添加一个控制台应用程序作为宿主:
在宿主中使用代码进行配置abc的操作:
using System; using System.ServiceModel; using WcfService1; namespace Hosting { class Program { static void Main(string[] args) { using (ServiceHost host = new ServiceHost(typeof(WcfService1.GeneralCalculator))) { host.AddServiceEndpoint(typeof(WcfService1.IGeneralCalculator), new BasicHttpBinding(), "http://localhost:8080/"); host.Open(); Console.Write("1111111111111111111111"); Console.ReadLine(); } } }
当然也可以使用配置的方式实现(在service端),终结点以相对地址写入:
<services> <service name="WcfService1.GeneralCalculator"> <host> <baseAddresses> <add baseAddress="http://localhost:8080"/> </baseAddresses> </host> <endpoint address="mex" binding="BasicHttpBinding" contract="WcfService1.IGeneralCalculator"> </endpoint> </service> </services>