What if you encounter a problem when consume your WCF service ? How to Diagnostic it ?
The Answer is the Log Tracing the WCF .
My service is:
[OperationContract(Name="Add")]
[WebInvoke(UriTemplate = "test/", Method = "POST",
ResponseFormat=WebMessageFormat.Json,
RequestFormat=WebMessageFormat.Json )]
public int Add(Number n1)
{
res = Convert.ToInt32(n1.Number1) + Convert.ToInt32(n1.Number2);
return res;
}
Data are..
[Serializable]
public class Number
{
public int Number1 { get; set; }
public int Number2 { get; set; }
}
When I call from fiddler its return ‘HTTP/1.1 400 Bad Request’
My fiddler request header is:
User-Agent: Fiddler Host: localhost:4217 Content-Type: application/json; charset=utf-8
And request body is:
{"Number1":"7","Number2":"7"}
And response header is:
HTTP/1.1 400 Bad Request Server: ASP.NET Development Server/10.0.0.0 Date: Sun, 14 Aug 2011 18:10:21 GMT X-AspNet-Version: 4.0.30319 Content-Length: 5450 Cache-Control: private Content-Type: text/html Connection: Close
The way you'll find out the issue with your code is to enable tracing on the server, and it will have an exception explaining the problem. I wrote a simple test with your code, and it had a similar error (400), and the traces had the following error:
The data contract type 'WcfForums.StackOverflow_7058942+Number' cannot be deserialized because the required data members '<Number1>k__BackingField, <Number2>k__BackingField' were not found.
See Also
posted on 2012-11-15 10:06 malaikuangren 阅读(349) 评论(0) 收藏 举报
浙公网安备 33010602011771号