尽管 WCF 服务方法成功返回(我通过设置断点验证),但我的 ajax 方法总是返回 ServiceFailed。代码如下所示。可能是什么问题?
function LoginToServer(name, password) {
server = "localhost:1706";
Type = "GET";
var encodeusername = $.base64.encode(encode_utf8(name.value));
var encodepwd = encode_utf8(password.value);
var params = 'username=' + encodeusername + '&password=' + encodepwd + '&clientip=none';
Url = "http://" + server + "/WCF/Test/TestService.svc/rest/Login?" + params;
ContentType = "application/json; charset=utf-8";
DataType = "jsonp";
ProcessData = true;
JsonpCallback = "alertResponse",
method = "Login";
CallService();
}
function CallService() {
$.ajax({
type: Type, //GET or POST or PUT or DELETE verb
url: Url, // Location of the service
data: Data, //Data sent to server
contentType: ContentType, // content type sent to server
dataType: DataType, //Expected data format from server
processdata: ProcessData, //True or False
jsonpCallback: JsonpCallback,
success: function (msg) {//On Successfull service call
ServiceSucceeded(msg);
},
error: ServiceFailed// When Service call fails
});
WCF服务方法定义如下:
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json,
UriTemplate = "/Login?username={username}&password={password}&clientip={clientip}")]
AuthenticationStatus SlideViewerLogin(string username, string password, string clientip);
谢谢。