WCF异常-处理请求时发生错误

本文关键字:错误 请求 异常 处理 WCF | 更新日期: 2023-09-27 18:15:00

我试图通过web服务访问数据。我的webservice调用工作得很好,但有时它抛出错误,而处理请求发生。See fault detail for additional information exception

下面是错误的堆栈跟踪:

  at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
  at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
  at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
  at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

我已经尝试在绑定中增加readerquota。这是我的绑定的样子

<bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IWS" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
          <readerQuotas
           maxDepth="2147483647"
           maxStringContentLength="2147483647"
           maxArrayLength="2147483647"
           maxBytesPerRead="2147483647"
           maxNameTableCharCount="2147483647" />
          <security mode="TransportWithMessageCredential" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://xxxx.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWS"
        contract="ABC.IWS" name="BasicHttpBinding_IWS" />
    </client>

WCF异常-处理请求时发生错误

我遇到了同样的问题,解决方案是设置被调用服务的所有参数。使用SOAPUI应用程序,您可能不会注意到它一次。但一如既往,提琴手说的是真话。例如,一开始您认为"important_parameters"足以设置为调用服务。你认为web服务考虑(/设置自己)"EndTo"参数为0…错了!你应该有意识地设置它,否则你会得到这篇文章中提到的错误。

...
<important_parameters>
   ....
</important_parameters>
<Paging>
   <EndTo>0</EndTo>
</Paging>
...

对我来说,第一个故障排除步骤是获取有关错误的更多信息。由于Task响应的工作方式,可能会有许多内部异常。因此,更改处理代码以记录内部异常。

var responseTask = client.someRemoteCall(request);
responseTask.ContinueWith(t =>
{
    switch (t.Status)
    {
        case TaskStatus.Faulted:
            foreach (var exception in t.Exception.Flatten().InnerExceptions)
            {
                log.Error(exception.Message);
                if (exception.InnerException != null)
                {
                    log.Error(exception.InnerException.Message);
                }
            }
            break;
        case TaskStatus.RanToCompletion:
            {your success code}
        default:
            {some deafult error is thrown}
    }
});