具有多个绑定的 ServiceHostFactory [英] ServiceHostFactory with multiple bindings

查看:20
本文介绍了具有多个绑定的 ServiceHostFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用具有多个绑定的 ServiceHostFactory?

How do I use a ServiceHostFactory with multiple bindings?

这是我尝试过的方法,但我不断遇到问题,一个又一个错误.

This is what I've tried and I keep getting issues, one after another error.

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 需要不同.

The uri needs to be different for each binding type.

TCP:net.tcp://{hostname}[:port]/{location}
基本 HTTP:http://{主机名}[:端口]/{位置}
WS HTTP:http://{hostname}:{port}/{location}

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

这篇关于具有多个绑定的 ServiceHostFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆