我的Web服务看起来像这样:
JavaScriptSerializer js = new JavaScriptSerializer();
[WebMethod]
public void FormSubmit(agentInfo agentInfoObject)
{
string agentID = "";
string agentName = "";
try
{
if (agentInfoObject != null)
{
agentID = agentInfoObject.agentID;
agentName = agentInfoObject.agentName;
}
else
{
Console.Write("No Data");
}
}
catch (Exception e)
{
Console.Write("Error :" + e.Message);
}
RequestBLObject.AgentID = agentInfoObject.agentID;
RequestBLObject.AgentName = agentInfoObject.agentName;
BehaviourBLObject.InsertDataBL(RequestBLObject);
}
进一步将BLL和DAL传递到工作正常的数据库(我使用SoapUI对其进行了测试)。当我尝试将此Web服务链接到我的HTML页面时,我无法获得任何输出。我正在使用JS调用此Web服务,看起来像这样:
$.ajax({
method: 'POST',
url: 'http://arohar.com/Service.asmx/FormSubmit',
data: "{info:" + JSON.stringify(info) + "}",
contentType: 'application/json; charset=utf-8',
processData: false,
dataType: 'JSON',
success: function() {
alert("in success");
},
error: function() {
alert('in error');
}
});
有人可以告诉我代码中哪里出了错吗?为什么我无法访问Web服务?
更新:我的AJAX响应如下所示:
`{"Message":"Invalid web service call, missing value for parameter: \u0027agentInfoObject\u0027.","StackTrace":" at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}`