我正在尝试使用 net.pipe 绑定为我的服务与客户端交互创建一个进程内单元测试。与良好的 WCF 服务一样,它在服务操作上使用FaultContractAttribute 来公开可能的错误(包装异常)到元数据。我想通过 XML 配置客户端和服务端点(应用程序配置)。然而,每当抛出错误时,它只是一个 CommunicationException“管道已关闭”,而不是我期望的类型错误。
System.ServiceModel.CommunicationException: There was an error reading from the pipe: The pipe has been ended. (109, 0x6d).
我尝试为 net.pipe 添加 IMetadataExchange 端点,但这不起作用。我也尝试过。在 Vista 上,需要我对 http 端点的 ACL 进行 netsh 操作。那也行不通。
自定义异常类:
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>
如果您上面描述的 ValidationException 类是您用于处理错误的类,那么它可能是问题的根源。您应该从FaultException 派生错误异常,因为它是可序列化的。 ApplicationException 不是。
Wagner 是对的,您需要用一个FaultContract 属性来装饰您的操作定义,并赋予它您的合约类型。您还应该使用 DataContract 和 DataMember 属性来装饰您的FaultContract。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)