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