以下 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/