简体   繁体   English

在IIS中托管WCF net.pipe绑定时控制命名管道的名称

[英]controlling the name of a named pipe when hosting WCF net.pipe binding in IIS

I have a service accessible via http and net.pipe. 我有一个可通过http和net.pipe访问的服务。 It is being hosted in IIS 7 (Server 2008). 它托管在IIS 7(Server 2008)中。 I may be hosting different instances of this service for several customers on the same machine and hence the HTTP is setup with virtual hostnames etc. This is all working fine. 我可能正在为同一台机器上的几个客户托管此服务的不同实例,因此HTTP设置为虚拟主机名等。这一切都正常。

I thought I would do similar for the net named pipe binding - using some form of the customers 'virtualhostname' in the named pipe base address, therefore allowing me to access the different customer instances with different net.pipe urns (I realize the net.pipe names are URN's not URL's so they can be essentially arbitrary but I thought I would follow a similar pattern to the HTTP addresses). 我以为我会做类似的网名命名管道绑定 - 在命名管道基地址中使用某种形式的客户'virtualhostname',因此允许我使用不同的net.pipe urns访问不同的客户实例(我意识到网络。管道名称是URN不是URL,因此它们可以基本上是任意的但我认为我会遵循与HTTP地址类似的模式)。

Here is my web.config 这是我的web.config

<service name="Administration" behaviorConfiguration="AdministrationBehavior">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="normalWsBinding" contract="IAdministration" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <endpoint address="" binding="netNamedPipeBinding" bindingConfiguration="normalNetNamedPipeBinding" contract="IAdministration" />
    <endpoint address="mex" binding="mexNamedPipeBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://virtualhostname.com/service" />
        <add baseAddress="net.pipe://virtualhostname.com/administration/service" />
      </baseAddresses>
    </host>
</service>

However, when accessing the WSDL for the service - the base address for the net.pipe seems to be ignored by IIS. 但是,在访问服务的WSDL时 - IIS似乎忽略了net.pipe的基址。 Instead I get the real hostname of the machine, and a net.pipe address URN that seems to have been formatted entirely by IIS. 相反,我得到了机器的真实主机名,以及似乎完全由IIS格式化的net.pipe地址URN。

<wsdl:port name="NetNamedPipeBinding_IAdministration" binding="tns:NetNamedPipeBinding_IAdministration">
   <soap12:address location="net.pipe://realhostname/service/Administration.svc"/>
   <wsa10:EndpointReference>
       <wsa10:Address>net.pipe://realhostname.com/service/Administration.svc</wsa10:Address>
       <Identity>
          <Spn>host/realhostname.com</Spn>
       </Identity>
   </wsa10:EndpointReference>
</wsdl:port>

With no control over the way net.pipe names are formed, I will not be able to discriminate between the multiple customer service instances on the machine. 由于无法控制net.pipe名称的形成方式,我将无法区分机器上的多个客户服务实例。 Does anyone have any clue as to how the net named pipe binding URN can be controlled within the IIS environment? 有没有人知道如何在IIS环境中控制网络命名管道绑定URN?

(I do a lot of standalone net.pipe hosting during testing (ie new ServiceHost()) so I know that my net.pipe bindings do work outside of IIS, and do allow control over the exact named pipe URN used) (我在测试期间做了很多独立的net.pipe托管(即新的ServiceHost())所以我知道我的net.pipe绑定在IIS之外工作,并且允许控制使用的确切命名管道URN)

If the names can't be controlled within IIS - does anyone have any experience with hosting and accessing multiple separate net.pipe service instances on the same machine? 如果无法在IIS中控制名称 - 是否有人在同一台计算机上托管和访问多个单独的net.pipe服务实例?

This is an old question, but I figured I'd add my answer since I also needed an answer for this (and maybe there are others out there who need it too). 这是一个老问题,但我想我会添加我的答案,因为我也需要一个答案(也许还有其他人也需要它)。

The base address of an IIS-hosted WCF service is controlled by IIS and cannot be overridden in web.config. IIS托管的WCF服务的基址由IIS控制,无法在web.config中重写。 Instead, you can control the base addresses by updating the IIS site binding information for the site you're hosting your service in. 相反,您可以通过更新您托管服务的站点的IIS站点绑定信息来控制基址。

Most of the documentation I found online suggests using * as the binding configuration for net.pipe. 我在网上找到的大多数文档建议使用*作为net.pipe的绑定配置。 But if you instead use "virtualsite.com" as the binding configuration value, the base address of your net.pipe endpoint will be "virtualsite.com" rather than the machine name. 但是,如果您使用“virtualsite.com”作为绑定配置值,则net.pipe端点的基址将是“virtualsite.com”而不是计算机名称。

Here is an example using appcmd to configure a site in IIS with the correct net.pipe binding: 以下是使用appcmd在IIS中使用正确的net.pipe绑定配置站点的示例:

%windir%\system32\inetsrv\appcmd.exe set site "Default Web Site" -+bindings.[protocol='net.pipe',bindingInformation='virtualhostname.com']

One note about HostnameComparisonMode , it has no effect in IIS according to MSDN : 关于HostnameComparisonMode的一个注意事项,根据MSDN ,它在IIS中没有任何影响:

These values have no effect when used inside of the Internet Information Services (IIS) or Windows Process Activation Service (WAS) hosting environment. 在Internet信息服务(IIS)或Windows进程激活服务(WAS)托管环境中使用时,这些值无效。 In those cases, WCF uses whatever hostname comparison mode is provided by the IIS Web Site hosting the WCF services. 在这些情况下,WCF使用托管WCF服务的IIS网站提供的任何主机名比较模式。

Instead, you have to use the mechanism I described above. 相反,你必须使用我上面描述的机制。 I figured this out by investigating how hostname binding works in HTTP for IIS. 我通过调查主机名绑定如何在HTTP中用于IIS来解决这个问题。 Unfortunately, I've not been able to find any official documentation for this IIS-based scenario for other WCF transports. 不幸的是,我无法为其他WCF传输的基于IIS的场景找到任何官方文档。

It appears that the host name portion of the URI is ignored and replaced by the implementation based upon the HostNameComparisonMode of the channel binding. 看来URI的主机名部分被忽略,并由基于通道绑定的HostNameComparisonMode的实现替换。 You can try changing it to "Exact" via the service's configuration... 您可以尝试通过服务配置将其更改为“Exact”...

http://msdn.microsoft.com/en-us/library/system.servicemodel.netnamedpipebinding.hostnamecomparisonmode.aspx http://msdn.microsoft.com/en-us/library/system.servicemodel.netnamedpipebinding.hostnamecomparisonmode.aspx

NetNamedPipeBinding.HostnameComparisonMode The HostnameComparisonMode value that indicates whether the hostname is used to reach the service when matching the URI. NetNamedPipeBinding.HostnameComparisonMode HostnameComparisonMode值,指示在匹配URI时是否使用主机名来访问服务。 The default value is StrongWildcard(), which ignores the hostname in the match. 默认值为StrongWildcard(),它忽略匹配中的主机名。

See the configuration syntax here: http://msdn.microsoft.com/en-us/library/ms731291.aspx 请参阅此处的配置语法: http//msdn.microsoft.com/en-us/library/ms731291.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM