且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

消费在C#JSON WCF服务

更新时间:2023-02-17 20:42:58

我观察,你的问题是与数据类型即可。在JavaScript调用,您设置的 datType JSONP

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

dataType: "jsonp"

而在你的Default.aspx.cs文件,你都发送纯JSON。有difference JSON和JSONP之间。

尝试在您的 Deafult.aspx.cs 文件改变JSON类型,然后运行。这可能会解决你的问题。

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

编辑:
改变你的合同为:

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;}
}