IIS WCF服务托管VS Windows服务WCF、IIS、Windows、VS

2023-09-02 10:19:53 作者:爷们不狠、何以霸天下

我们开发了一个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?

我们也看到在计算器,当一个WCF服务主机在IIS(见WCF服务配置文件的问题对于< baseAddresses> )

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,你必须让你的网站的高级设置中绑定可用。之后,您将设置新的为您的网站Web服务的结合,并添加你想要听每一个绑定,并指定地址。

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 normaly,并添加一个新的绑定的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.