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

发布于 2024-08-12 05:15:54 字数 2042 浏览 7 评论 0原文

我有一个通过 http 和 net.pipe 访问的服务。它托管在 IIS 7 (Server 2008) 中。我可能在同一台机器上为多个客户托管此服务的不同实例,因此 HTTP 是使用虚拟主机名等设置的。这一切都工作正常。

我想我会对网络命名管道绑定做类似的事情 - 使用某种形式 命名管道基地址中的客户“虚拟主机名”,因此允许我 使用不同的 net.pipe urns 访问不同的客户实例(我意识到 net.pipe 名称是 URN 而不是 URL,因此它们本质上可以是任意的,但是 我想我会遵循与 HTTP 地址类似的模式)。

这是我的 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>

但是, 当访问服务的 WSDL 时 - net.pipe 的基地址似乎 被 IIS 忽略。相反,我得到了机器的真实主机名,以及 net.pipe 地址 URN 似乎已完全由 IIS 格式化。

<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>

由于无法控制 net.pipe 名称的形成方式,我将无法区分 机器上的多个客户服务实例之间。有谁知道如何 net命名管道绑定URN可以在IIS环境内控制吗?

(我在测试期间做了很多独立的 net.pipe 托管(即 new ServiceHost()) 所以我知道我的 net.pipe 绑定可以在 IIS 之外工作,并且允许控制 通过使用的确切命名管道 URN)

如果无法在 IIS 中控制名称 - 是否有人有任何经验 在同一台主机上托管和访问多个单独的 net.pipe 服务实例 机器?

I have a service accessible via http and net.pipe. It is being hosted in 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.

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).

Here is my 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. Instead I get the real hostname of the machine, and a
net.pipe address URN that seems to have been formatted entirely by IIS.

<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. Does anyone have any clue as to how
the net named pipe binding URN can be controlled within the IIS environment?

(I do a lot of standalone net.pipe hosting during testing (i.e. 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)

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

無心 2024-08-19 05:15:54

这是一个老问题,但我想我应该添加我的答案,因为我也需要这个答案(也许还有其他人也需要它)。

IIS 托管的 WCF 服务的基地址由 IIS 控制,不能在 web.config 中覆盖。相反,您可以通过更新托管服务的站点的 IIS 站点绑定信息来控制基地址。

我在网上找到的大多数文档都建议使用 * 作为 net.pipe 的绑定配置。但是,如果您使用“virtualsite.com”作为绑定配置值,则 net.pipe 端点的基址将是“virtualsite.com”而不是计算机名称。

下面是一个使用 appcmd 在 IIS 中配置具有正确 net.pipe 绑定的站点的示例:

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

关于 HostnameComparisonMode 的一个注释,根据 MSDN

这些值在 Internet 信息服务 (IIS) 或 Windows 进程激活服务 (WAS) 托管环境中使用时无效。在这些情况下,WCF 使用托管 WCF 服务的 IIS 网站提供的任何主机名比较模式。

相反,您必须使用我上面描述的机制。我通过研究 IIS 的 HTTP 中的主机名绑定如何工作,发现了这一点。不幸的是,我无法找到有关其他 WCF 传输的基于 IIS 的方案的任何官方文档。

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. Instead, you can control the base addresses by updating the IIS site binding information for the site you're hosting your service in.

Most of the documentation I found online suggests using * as the binding configuration for 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.

Here is an example using appcmd to configure a site in IIS with the correct net.pipe binding:

%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:

These values have no effect when used inside of the Internet Information Services (IIS) or Windows Process Activation Service (WAS) hosting environment. In those cases, WCF uses whatever hostname comparison mode is provided by the IIS Web Site hosting the WCF services.

Instead, you have to use the mechanism I described above. I figured this out by investigating how hostname binding works in HTTP for IIS. Unfortunately, I've not been able to find any official documentation for this IIS-based scenario for other WCF transports.

冷了相思 2024-08-19 05:15:54

URI 的主机名部分似乎被忽略并被基于通道绑定的 HostNameComparisonMode 的实现所替换。您可以尝试通过服务的配置将其更改为“精确”...

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

NetNamedPipeBinding.HostnameComparisonMode
HostnameComparisonMode 值,指示匹配 URI 时是否使用主机名来访问服务。默认值为 StrongWildcard(),它会忽略匹配中的主机名。

请参阅此处的配置语法:
http://msdn.microsoft.com/en-us/library/ms731291。 ASPX

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. You can try changing it to "Exact" via the service's configuration...

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. The default value is StrongWildcard(), which ignores the hostname in the match.

See the configuration syntax here:
http://msdn.microsoft.com/en-us/library/ms731291.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文