我正在尝试使用 net.pipe 绑定为我的服务与客户端交互创建一个进程内单元测试。与良好的 WCF 服务一样,它在服务操作上使用 FaultContractAttribute 将可能的错误(包装异常)暴露给元数据。我想通过 XML (App.config) 配置客户端和服务端点。 但是,每当抛出错误时,它只是一个 CommunicationException“管道已关闭”,而不是我所期望的类型错误。
System.ServiceModel.CommunicationException: There was an error reading from the pipe: The pipe has been ended. (109, 0x6d).
我尝试为 net.pipe 添加 IMetadataExchange 端点,但这不起作用。我也试过了。在 Vista 上需要我为 http 端点 netsh 的 ACL。那也没有用。
自定义异常类:
public class ValidationException : ApplicationException { }
这是配置的最新尝试,但它抽出“在服务实施的合同列表中找不到合同名称'IMetadataExchange'”
任何有关如何完成此操作的示例或建议的链接将不胜感激。
<system.serviceModel>
<client>
<endpoint name="Client"
contract="IService"
address="net.pipe://localhost/ServiceTest/"
binding="netNamedPipeBinding"
bindingConfiguration="netPipeBindingConfig" />
</client>
<services>
<service
name="Service"
behaviorConfiguration="ServiceFaults">
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/ServiceTest/"/>
<add baseAddress="http://localhost/ServiceTest/"/>
</baseAddresses>
</host>
<endpoint
address=""
binding="netNamedPipeBinding"
bindingConfiguration="netPipeBindingConfig"
name="ServicePipe"
contract="IService" />
<endpoint
address="MEX"
binding="mexNamedPipeBinding"
bindingConfiguration="mexNetPipeBindingConfig"
name="MexUserServicePipe"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<netNamedPipeBinding>
<binding name="netPipeBindingConfig"
closeTimeout="00:30:00"
sendTimeout="00:30:00" />
</netNamedPipeBinding>
<mexNamedPipeBinding>
<binding name="mexNetPipeBindingConfig"></binding>
</mexNamedPipeBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceFaults">
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior name="MEX">
<serviceMetadata
httpGetEnabled="true"
httpGetUrl="http://localhost/ServiceTest/MEX"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>