2014-04-04 93 views
1

我有一个WCF服务已将includeExceptionDetailInFaults设置为true。当我在SOAP UI测试该服务,我可以看到,响应包含错误:WCF客户端没有得到服务异常

<ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
    <HelpLink i:nil="true"/> 
    <InnerException i:nil="true"/> 
    <Message>Invalid Session Protocol</Message> 

然而,我的客户只是拿起一个很平淡

The remote server returned an unexpected response: (400) Bad Request.

消息。因此,为了使其能够读取服务的响应,我必须在客户端中执行某些操作。

我服务的配置是这样的:

<system.serviceModel> 
    <client> 
     <endpoint 
      address="http://az00439/DRGDataService/StoreDataDotNet.svc" 
      binding="basicHttpBinding" bindingConfiguration="" 
      contract="DRGDataService.IStoreDataDotNet" 
      name="DotNetClient" kind="" endpointConfiguration=""> 
      <identity> 
       <certificateReference storeName="My" storeLocation="LocalMachine" 
            x509FindType="FindBySubjectDistinguishedName"/> 
      </identity> 
     </endpoint> 
    </client> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="basicBinding"> 
      <security mode="TransportCredentialOnly"> 
      </security> 
     </binding> 
     </basicHttpBinding> 
     <webHttpBinding> 
     <binding name="webBinding"> 
      <security mode="Transport"> 
       <transport clientCredentialType="None"/> 
      </security> 
     </binding> 
     </webHttpBinding> 
    </bindings> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="AspNetAjaxBehavior"> 
      <enableWebScript/> 
     </behavior> 
     <behavior name="webEndpoint"> 
      <webHttp defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Json" 
         helpEnabled="true"/> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior name="StoreDataBehaviour"> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true" 
          httpsHelpPageUrl="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
           multipleSiteBindingsEnabled="true"/> 
    <services> 
     <service behaviorConfiguration="StoreDataBehaviour" name="DRGDataLibrary.StoreData"> 
      <host> 
      <baseAddresses> 
       <add baseAddress="https://az00439/DRGDataService/StoreData.svc"/> 
      </baseAddresses> 
      </host> 
      <endpoint name="StoreDatawebHTTPBindingEndpoint" 
       address="" 
       behaviorConfiguration="AspNetAjaxBehavior" 
       binding="webHttpBinding" bindingConfiguration="webBinding" 
       contract="DRGDataLibrary.StoreData" /> 
    </service> 
    <service name="DRGDataLibrary.StoreDataDotNet" 
     behaviorConfiguration="StoreDataBehaviour" > 
     <host> 
      <baseAddresses> 
       <add baseAddress="https://az00439/DRGDataService/StoreDataDotNet.svc"/> 
       <add baseAddress="http://az00439/DRGDataService/StoreDataDotNet.svc"/> 
      </baseAddresses> 
     </host> 
     <endpoint name="StoreDataDotNetWebHttpEndpoint" 
      address="" 
      behaviorConfiguration="webEndpoint" 
      binding="webHttpBinding" bindingConfiguration="webBinding" 
      contract="DRGDataLibrary.IStoreDataDotNet" /> 

     <endpoint name="StoreDataDotNetBasicHttpEndpoint" 
      address="http://az00439/DRGDataService/StoreDataDotNet.svc" 
      behaviorConfiguration="" 
      binding="basicHttpBinding" bindingConfiguration="basicBinding" 
      contract="DRGDataLibrary.IStoreDataDotNet" /> 
     </service> 
    </services> 
</system.serviceModel> 

(有一个在此配置公平一点事情,因为我使用SSL,使JS调用的服务)

感谢

尼克赖特

回答

0

你捕捉什么样的异常类型?如果它只是非通用的FaultException,则无法访问该服务提供的任何故障特定细节。

启用includeExceptionDetailInFaults,它看起来像WCF使用ExceptionDetail数据合同编码你在了SoapUI看到的信息,这意味着你应该能够赶上FaultException<ExceptionDetail>和检查异常的Detail属性来弄个。

所有这一切说,该official recommendation是使用includeExceptionDetailInFaults仅用于调试,并build better error-reporting mechanisms自定义错误契约和IErrorHandler - 所以这是有疑问的客户应在ExceptionDetail依托信息反正。

+0

嗨 - 谢谢你的回答。还没有机会回到这个,但是当我这样做的时候会尝试你的建议。 –

相关问题