zoukankan      html  css  js  c++  java
  • 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

    http://msdn.microsoft.com/en-us/library/ms733025.aspx

  • 相关阅读:
    vim技巧2
    vim技巧1
    网站压力测试工具
    CentOS mysql安装
    破解root
    渐进式性能监测案例
    网络监测介绍
    I/O检测介绍
    虚拟内存介绍
    @Slf4j
  • 原文地址:https://www.cnblogs.com/malaikuangren/p/2771034.html
Copyright © 2011-2022 走看看