如何使用具有多个绑定的 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;
}
}
}
每种绑定类型的 uri 都需要不同。
TCP:
net.tcp://{主机名}[:端口]/{位置}
基本 HTTP:
http://{主机名}[:端口]/{位置}
WS HTTP:
http://{主机名}:{端口}/{位置}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)