【问题标题】:WCF - convert HTTP to Named PipeWCF - 将 HTTP 转换为命名管道
【发布时间】:2014-03-20 18:29:46
【问题描述】:

伙计们,我一直在查看大量博客,本周发布了 SO 帖子,但我仍然不确定如何将我的 WCF 服务从 HTTP 绑定转换为使用命名管道。 我认为有不同的方法可以做到这一点,但我正在使用 web.configs 并在我的代码中使用服务引用。

与其详细说明我尝试过的所有内容,我可以问这个问题吗?

从 HTTP 绑定到命名管道需要采取哪些步骤?

我是否需要我在(某些)博客/SO 帖子中提到的这个 MEX 东西? 我知道我需要将 IIS 设置为启用的协议:net.pipe... 并且 IIS Express 不支持这个(花了一个下午!)

一些相关的代码,我现在有的:

在 IEmployeeData 中:

namespace Mobile.ServiceLayer {
[ServiceContract]
public interface IEmployeeData
{ ... }

调用 WCF 服务:

string endpointConfigName = "BasicHttpBinding_IEmployeeData";
        EmployeeSvcRef.EmployeeDataClient edc = new EmployeeSvcRef.EmployeeDataClient(endpointConfigName);
        EmployeeSvcRef.EmployeeListResponse emp = edc.EmployeeList();

WCF 服务 web.config:

 <services>
  <service name="Mobile.ServiceLayer.EmployeeData">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:62734/EmployeeData" />
      </baseAddresses>
    </host>
  </service>

...

<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" />
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

客户端 web.config:

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IEmployeeData" />

...

<client>
  <endpoint address="http://localhost:62734/EmployeeData.svc" binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_IEmployeeData" contract="EmployeeSvcRef.IEmployeeData"
    name="BasicHttpBinding_IEmployeeData" />

就像我说的那样,我看过 SO 的帖子和博客,但似乎总是缺少一块拼图!

编辑:向导后的客户端 web.config:

<endpoint address="net.pipe://localhost/EmployeeData.svc/" binding="netNamedPipeBinding"
    bindingConfiguration="NewBinding0" contract="IEmployeeData"
    name="" kind="" endpointConfiguration="">
    <identity>
      <certificateReference storeName="My" storeLocation="LocalMachine"
        x509FindType="FindBySubjectDistinguishedName" />
    </identity>
  </endpoint>

【问题讨论】:

  • 右击服务Web.config文件并选择“编辑WCF配置”。您将看到一个Binding 文件夹,右键单击它并创建一个新的netNamedPipeBinding,然后转到Client-&gt;Endpoints,右键单击您现有的文件夹或创建一个新文件夹并告诉它使用您的 NamedPipe 绑定。
  • 我没有读过这个工具。当我转到树视图中的 Client -> Endpoints 文件夹时,没有可供选择的现有端点。如果我创建一个新的,我如何告诉它使用我的 NamedPipe 绑定?我无法在 Binding 中输入名称。
  • 您的 NamedPipe 绑定应该有自己的 BindingConfiguration 名称,您只需在设置 EndPoint 时在可用绑定配置的下拉列表中选择正确的名称
  • 好吧,这取决于您是否公开多个端点。你试过WcftestClient吗?
  • 如果你的NamedPipe绑定正确设置了uo服务器端,进入消费者网站,右击“Edit WCF Configuration”,右击Client文件夹并新建一个。有一个手动的分步过程,可以让您获取 wcf 服务 DLL(在 wcf 项目的 /bin 文件夹中)并为您编写正确的配置。

标签: wcf named-pipes


【解决方案1】:

好的,这就是我所做的。您可能会发现使用 Max 的 cmets 中提到的内置工具更容易。右键单击 web.config 并选择编辑 WCF 配置。首先完成 WCF 服务,如果设置了端点,在客户端上运行它(右键单击它的 web.config)将为您提供一个向导。

服务器 WEB.CONFIG

服务名称是接口的完全限定名称,例如Mobile.ServiceLayer.IEmployeeData

基地址变为

net.pipe://localhost/EmployeeData.svc

。请注意,端口号已被删除并且 .svc 存在(!)

创建一个端点,契约是您的接口和类型为 netNamedPipeBinding 的绑定。

为 MEX 添加第二个端点,即 MetadataEXchange。

将 ServiceMetaData httpGetEnabled 设置为 false。

<system.serviceModel>
<services>
  <service name="Mobile.ServiceLayer.IEmployeeData">
    <host>
      <baseAddresses>
        <add baseAddress="net.pipe://localhost/EmployeeData.svc" />
      </baseAddresses>
    </host>
    <!-- NetPipe -->
    <endpoint
      address=""
      binding="netNamedPipeBinding"
      contract="IEmployeeData" name="MyNetPipe" />
    <!-- Mex (Net.Tcp / Net.Pipe ) -->
    <endpoint name="EmployeeDataNetPipeMex" address="mex" binding="mexNamedPipeBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

客户端 WEB.CONFIG

从“basicHttpBinding”中删除绑定条目

使用名为 NetNamedPipeBinding_IEmployeeData 的条目添加部分 在“客户端”中添加一个带有地址的端点

net.pipe://localhost/EmployeeData.svc

合约是'referencename'.'interface'

    <bindings>
  <basicHttpBinding>
  </basicHttpBinding>
  <netNamedPipeBinding>
    <binding name="NetNamedPipeBinding_IEmployeeData" />
  </netNamedPipeBinding>
</bindings>
<client>
  <endpoint address="net.pipe://localhost/EmployeeData.svc" binding="netNamedPipeBinding"
    bindingConfiguration="NetNamedPipeBinding_IEmployeeData" contract="EmployeeSvcRef.IEmployeeData"
    name="NetNamedPipeBinding_IEmployeeData" />
    </client>

【讨论】:

  • port 怎么不在 netNamedPipeBinding 地址中,我也有这个问题。
  • @NickN。命名管道不像 TCP/IP 那样在端口上运行。它们通过 MMF 处理路径接口。更多信息在这里 - stackoverflow.com/a/5804057/105539
猜你喜欢
  • 2011-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多