由於某種原因,我的web服務不喜歡我發送的數據。我不斷收到以下錯誤:.Net Webservice不會接受XML調用的參數
System.InvalidOperationException: Request format is invalid: text/xml; charset=utf-8.
在System.Web.Services.Protocols.HttpServerProtocol.ReadParameters() 在System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
任何想法?
這裏是我的代碼:
$.ajax({
type: "POST",
url: "/wsCheckout.asmx/loginUser",
data: "userName=" + userName + "&pw=" + pw,
contentType: "text/xml; charset=utf-8",
dataType: "xml",
cache: false,
beforeSend: function(n){ showLoading(); },
complete: function(n){ hideLoading(); },
success: function(r) {
if(checkResponse(r) == true){
closeBox(aspxIdPrefix + "login");
hideBox(aspxIdPrefix + "login");
openBox("#shippingAddress");
}
} // end success
}); //end AJAX
[WebMethod(EnableSession = true)]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Xml)]
public DataTable loginUser(string userName, string pw)
{
......
}
請問你的web服務接受輸入XML的形式?爲什麼你需要設置上面的contentType參數? – shahkalpesh 2009-05-22 23:36:35
這是我的猜測。您正在將contentType設置爲xml,但數據不是xml格式。 – shahkalpesh 2009-05-22 23:41:25