gpt4 book ai didi

c# - 具有多个绑定(bind)的 ServiceHostFactory

转载 作者:太空宇宙 更新时间:2023-11-03 11:43:44 24 4
gpt4 key购买 nike

如何使用具有多个绑定(bind)的 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;
}
}
}

最佳答案

每种绑定(bind)类型的 uri 需要不同。

TCP: net.tcp://{hostname}[:port]/{location}
Basic HTTP: http://{hostname}[:port]/{location}
WS HTTP: http://{hostname}:{port}/{location}

关于c# - 具有多个绑定(bind)的 ServiceHostFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3970630/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com