WCF客户端没有从服务中获得异常

时间:2014-04-04 08:04:33

标签: wcf

我有一个WCF服务,includeExceptionDetailInFaults设置为true。当我在SOAP UI中测试服务时,我可以看到响应包含错误:

<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>

然而,我的客户只是选择了一个非常沉闷的

  

远程服务器返回了意外响应:(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调用)

由于

Nick Wright

1 个答案:

答案 0 :(得分:0)

你捕捉到什么异常类型?如果它只是一个非泛型FaultException,则无法访问该服务提供的任何特定于故障的详细信息。

当您启用includeExceptionDetailInFaults时,看起来WCF使用ExceptionDetail数据合同来编码您在SoapUI中看到的信息,这意味着您应该能够通过捕获{来获取它{1}}并检查异常的FaultException<ExceptionDetail>属性。

所有这一切,official recommendation仅使用Detail进行调试,build better error-reporting mechanisms使用自定义错误合同和includeExceptionDetailInFaults - 因此,您的客户是否应该是无论如何依赖IErrorHandler中的信息。