IIS WCF 服务托管与 Windows 服务 [英] IIS WCF service hosting vs Windows Service

查看:24
本文介绍了IIS WCF 服务托管与 Windows 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们开发了一个 WCF 服务,并且正在寻求部署它.我们的客户将把它与 basicHttpBinding 一起使用,但我们的内部团队将把它与 namedPipesBinding 一起使用.

We developed a WCF service and we're looking to deploy it. Our clients will be using it with basicHttpBinding but our internal team will be using it with namedPipesBinding.

我们想知道是将它托管在 IIS 7 中还是使用 Windows 服务更好.我们运行了一些测试,我们发现当我们在 IIS 中添加绑定时,它不会更新我们服务的配置文件.这意味着我们需要在两个不同的地方维护配置.这不合逻辑,对吧?

We are wondering if is it better to host it in IIS 7 or with a Windows Service. We ran some tests and we found out that when we're adding bindings in IIS, it doesn't update config file of our service. That means that we would need to maintain the configuration in two different places. It's not logical, right?

我们还在 StackOverflow 上看到,当 WCF 服务在 IIS 中托管时,基地址会被忽略(参见 关于<baseAddresses>的WCF服务配置文件问题)

We also read on StackOverflow that the base address is ignored when a WCF service is host in IIS (see WCF service configuration file question regarding <baseAddresses>)

推荐答案

回答这些问题:

我们进行了一些测试,我们发现当我们添加绑定时IIS,它不更新配置文件我们的服务.这意味着我们会需要保持配置在两个不同的地方.这不是逻辑,对吗?

We ran some tests and we found out that when we're adding bindings in IIS, it doesn't update config file of our service. That means that we would need to maintain the configuration in two different places. It's not logic, right ?

当您使用 IIS 托管您的服务时,您必须配置您的 App.config 文件或 web.config 文件以允许 IIS 公开一些绑定,因此在您的配置文件中,您将把您允许的所有绑定放到您的 wcf服务.Http、net.tcp 等...

When you use IIS to host your service, you must configure your App.config file or web.config file to allow IIS to expose some binding, so in your configuration file, you will put all your binding you allow to your wcf service. Http, net.tcp etc...

在您的绑定中您不会指定地址,因为您将直接在 IIS 中指定这些地址.

In your binding you will not specified address, because you will specified those address in IIS directly.

在 IIS 中,您必须允许在您网站的高级设置中可用的绑定.之后,您将为您的网站网络服务"设置新的绑定并添加您想要监听的所有绑定,并指定地址.

In IIS you must allow the binding available in the advanced settings of your web site. After that you will set new binding for your web site "web service" and add every bindings you want listen, and specify the address.

您将直接在 IIS 中指定地址.

You will specify the address directly in IIS.

有一个例子.

您的配置文件:

<services>
    <service name="ServiceName">                    
        <endpoint address=""
            binding="basicHttpBinding"
            bindingConfiguration="httpMode"
            contract="IContract" />                 
        <endpoint address=""
            binding="netTcpBinding"
            contract="IContract" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
</services>

在您的 IIS 高级设置中,您将把

In your IIS advenced setting your will put

启用协议中的http,net.tcp

http,net.tcp in Enabled Protocols

之后,您将绑定到 IIS.把你的 http 绑定正常并添加一个新的绑定 net.tcp,在绑定配置中放置端口和虚拟目录,如

After that you will go in your binding into IIS. Put your binding for http normaly and add a new binding net.tcp, in the binding configuration put the port and virtual directory like

8001:*

此设置允许所有连接到任何虚拟目录的 8001 端口.

This setting allow all connection into the 8001 port for any virtual directory.

您还必须在您的服务器上安装WCF 激活,(Http 激活和非 Http 激活)"功能.

You also must to have the feature "WCF Activation, (Http activation and Non-Http Activation)" installed on your server.

这篇关于IIS WCF 服务托管与 Windows 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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