WCF热带鱼书学习手记 - endpoint
endpoint的作用就是发布服务,它必须包含WCF中A, B和C三个方面的定义,缺一不可。从配置文件上来看
<system.serviceModel>
<services>
<service name="MyNamespace.MyService">
<endpoint contract = "MyNamespace.IMyService"
binding = "wsHttpBinding"
address = "http://localhost:8000/MyService"
/>
</service>
</services>
</system.serviceModel>
相同的服务可以在多个endpoint上发布,但是要确保address不同,例如:
<system.serviceModel>
<services>
<service name="MyNamespace.MyService">
<endpoint contract = "MyNamespace.IMyService"
binding = "wsHttpBinding"
address = "http://localhost:8001/MyService"
/>
<endpoint contract = "MyNamespace.IMyService"
binding = "wsHttpBinding"
address = "http://localhost:8002/MyService"
/>
</service>
</services>
</system.serviceModel>
在self-host的情况下,可以用过代码配置endpoint
ServiceHost host = new ServiceHost(typeof(MyService));
Binding wsHttpBinding = new WSHttpBinding();
host.AddServiceEndpoint(typeof(IMyService),
wsHttpBinding,
new Uri("http://localhost:8086/MyService/"));
host.Open();
...
host.Close();
浙公网安备 33010602011771号