gpt4 book ai didi

WCF - 将 HTTP 转换为命名管道

转载 作者:行者123 更新时间:2023-12-01 12:43:04 25 4
gpt4 key购买 nike

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

我可以问这个问题,而不是在这里详细说明我尝试过的所有内容吗?

What are the steps I need to take to go from HTTP Binding to Named Pipes?

我是否需要我在(某些)博客/SO 帖子中看到的这个 MEX 东西?我知道我需要将 IIS 设置为启用的协议(protocol):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 帖子和博客,但似乎总有一 block 拼图不见了!

编辑:向导后的客户端 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>

最佳答案

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

服务器网络配置

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

基地址变为

net.pipe://localhost/EmployeeData.svc

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

创建一个端点,契约(Contract)是您的接口(interface)和 netNamedPipeBinding 类型的绑定(bind)。

为 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”中删除绑定(bind)条目

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

net.pipe://localhost/EmployeeData.svc

契约(Contract)是'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>

关于WCF - 将 HTTP 转换为命名管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22542026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com