如何将ServiceHostFactory与多个绑定结合使用?
这就是我所尝试过的,我不断遇到问题,一个又一个错误。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Web.Services.Description;
using System.ServiceModel.Description;
using System.ServiceModel.Channels;
namespace WcfService7
{
public class clsMyOwnServiceHost : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type t, Uri[] baseAddresses)
{
NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
BasicHttpBinding basicbinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
WSHttpBinding wsbinding = new WSHttpBinding(SecurityMode.None);
ServiceHost host = new ServiceHost(t, baseAddresses);
foreach(Uri uri in baseAddresses)
{
host.AddServiceEndpoint(typeof(IService1), basicbinding, uri);
host.AddServiceEndpoint(typeof(IService1), wsbinding, uri);
host.AddServiceEndpoint(typeof(IService1), binding, uri);
}
return host;
}
}
}
答案 0 :(得分:2)
每种绑定类型的uri需要不同。
TCP: 的net.tcp:// {主机名} [:端口] / {位置}
基本HTTP: HTTP:// {主机名} [:端口] / {位置}
WS HTTP: HTTP:// {主机名}:{端口} / {位置}