我从ajax调用WCF服务,我可以让它作为GET请求而不是POST请求.所以:
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public UserObject GetUser(string name)
{
// Add your operation implementation here
var uo = new UserObject() { CustClass = "Guest", fname = "Chris", Email = "chris@Something", IsMobile = false };
uo.fname = name;
return uo;
}
Run Code Online (Sandbox Code Playgroud)
和
var json = { "name": "test" };
$.ajax({ //get user name and customer class
type: "GET",
url: "WritingAnalysisService.svc/GetUser",
data: json,
processData: true,
contentType: "application/json",
timeout: 10000,
dataType: "json",
cache: false,
success: function …Run Code Online (Sandbox Code Playgroud)