错误请求:将字符串从Android客户端发送到.NET REST服务
我正试图从我的android客户端(android 4.03)发送一个json字符串 到我的.net Rest服务(WCF)。我得到了“坏请求”作为回应。我有.NET tester用于此服务,它工作正常 服务器端代码:错误请求:将字符串从Android客户端发送到.NET REST服务,android,.net,rest,Android,.net,Rest,我正试图从我的android客户端(android 4.03)发送一个json字符串 到我的.net Rest服务(WCF)。我得到了“坏请求”作为回应。我有.NET tester用于此服务,它工作正常 服务器端代码: [WebInvoke(UriTemplate = "submit", Method = "POST", RequestFormat = WebMessageFormat.Json)] public bool SubmitPackage(string instance) {
[WebInvoke(UriTemplate = "submit", Method = "POST", RequestFormat = WebMessageFormat.Json)]
public bool SubmitPackage(string instance)
{
log.WriteWarning("Submit");
return true;
}
我的WCF配置
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" maxReceivedMessageSize="327680" helpEnabled="true" automaticFormatSelectionEnabled="false" defaultOutgoingResponseFormat="Json" transferMode="Buffered" />
</webHttpEndpoint>
</standardEndpoints>
您的WCF服务是否托管在IIS中?打开失败请求日志记录并查看结果 还可以使用fiddler查看发送的流量。您可以将fiddler配置为在服务器上运行。它通常在客户端上运行,但不能在Android上运行 要将fiddler配置为在服务器上运行 而且我经常把它放在我的web.config中
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\logs\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
它记录与请求相关的错误。这可以打开并解析请求
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\logs\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>