c# - 我如何调查 WCF 通过 GET 给出 400 个错误请求?

标签 c# wcf

以下 WCF 端点与 WCF 测试客户端一起工作得很好:

[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Xml,
        BodyStyle = WebMessageBodyStyle.Bare,
        UriTemplate = "listflaggedassets/{platform}?endpoint={endpoint}&pid={portalid}&processCode={processCode}&index={index}&limit={limit}")]
AssetList ListFlaggedAssets(short processCode, string platform, string endpoint = "null", string portalId = "null", int index = 0, int limit = 12);

但是,当我尝试导航到 URL http://localhost/DigitalREST/XosAssets.svc/listflaggedassets/SEC?endpoint=superfan&pid=0&processCode=0&index=0&limit=20 时,我得到了一个400 错误请求。

我似乎找不到任何方法来弄清楚为什么我收到错误的请求,并且附加到 IIS 进行调试不会因任何异常而中断。

如何调查错误请求的原因?

最佳答案

您可以启用跟踪并使用 Service Trace Viewer

将其放入您的 app.config(记录源 taken from this answer):

<system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true" >
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
      <source name="myUserTraceSource"
              switchValue="Information, ActivityTracing">
        <listeners>
          <add name="xml"/>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xml"
           type="System.Diagnostics.XmlWriterTraceListener"
           initializeData="TraceLog.svclog" />
    </sharedListeners>
  </system.diagnostics>

然后,在服务跟踪查看器中打开 TraceLog.svclog。它可能不会准确告诉您发生了什么,但会提供有关流量和异常本身的详细信息。

您可能还想检查在调试器中启用的异常。在 Visual Studio 中,转到 Debug -> Exceptions 并检查是否检查了正确的框架。

关于c# - 我如何调查 WCF 通过 GET 给出 400 个错误请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9897201/

相关文章:

c# - 服务器应用程序的多个客户端超过 15 个客户端处理问题

c# - WCF服务和AJAX调用问题

jquery - 如何使用 jquery POST 到 WCF

c# - 自定义模块,可以将模块添加到模块中以在 DNN 9.2 中创建扩展模块

c# - File.Exists 使用了错误的根路径?

c# - 在一个 SqlCe 命令中创建多个表不起作用

visual-studio-2010 - 用于 WCF 负载测试的负载 UI 与 Visual Studio 2010

jquery - 测试/构建 MSDN 文章 "JSON with Padding (AJAX) "

wcf - 每个配置文件 'DbProviderFactories'部分只能出现一次

c# - 当 '\' 后跟成为有效转义序列的字符时,在 '\' 字符上拆分字符串