Consume JSON WCF services in C#

后端 未结 1 1253
旧时难觅i
旧时难觅i 2021-01-29 02:08

I want to consume my json wcf web service from the code behind of my page:

Default.aspx.cs

string result = url + \"/ExecuteAction?callback=?\";
var httpW         


        
相关标签:
1条回答
  • 2021-01-29 02:16

    I am observing that your problem is with DataType. In your Javascript call, you are setting datType as jsonp

    dataType: "jsonp"
    

    And in your Default.aspx.cs file you are sending plain JSON. There is difference between JSON and JSONP.

    Try changing JSON type in your Deafult.aspx.cs file and then run. This might resolve your problem.

    EDIT: Change your Contract as:

    [OperationContract]
    [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "json")]
    public string ExecuteAction(JSONRequest request)
    {
       String JSONResult = String.Empty;
       MethodInfo action = services.GetMethod(action, BindingFlags.NonPublic |    BindingFlags.Public | BindingFlags.Static);
       JSONResult =(String)action.Invoke(null, new object[] { args });
    }
    
    [DataContract]
    public class JSONRequest
    {
       [DataMember]
       public string Action {get; set;}
       [DataMember]
       public string Args {get; set;}
    }
    
    0 讨论(0)
提交回复
热议问题