I've researched this issue all day and it seems to be a somewhat mon problem, but I have not been able to find a solution.
I am using jquery's $.ajax()
function to make a service call that updates some values in the database. It runs fine on localhost, but on the actual server I get a 500 Internal Server Error in the console window.
My client-side code is as below:
var param = FunctionToMakeKeyValueString();
$.ajax({
type: "POST",
url: "../Helpers/Autoplete.asmx/OrderStatements",
data: { param: param },
clientType: "application/json; charset=utf-8",
datatype: "json",
async: true,
success: function () { ShowSuccess();},
error: function () { ShowError(); }
});
And server-side code is:
[WebService(Namespace = "/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, unment the following line.
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService {
public AutoComplete () {
//Unment the following line if using designed ponents
//InitializeComponent();
}
[WebMethod]
public void OrderStatements(string param)
{
IneStatementService service = new IneStatementService();
string[] ps = param.Split(';');
foreach (string s in ps)
{
int id;
short order;
string[] pieces = s.Split(':');
if (int.TryParse(pieces[0], out id) && short.TryParse(pieces[1], out order))
{
IneStatement statement = service.FindBy(id);
statement.Order = order;
service.UpdateOrder(statement);
}
}
}
}
the actual asmx file is just
<%@ WebService Language="C#" CodeBehind="~/App_Code/AutoComplete.cs" Class="AutoComplete" %>
I'm sure the url is correct (the .js file is in a sibling folder to Helpers, which contains the asmx), but is there something else that I need to set in IIS or the web.config file? Thanks!
I've researched this issue all day and it seems to be a somewhat mon problem, but I have not been able to find a solution.
I am using jquery's $.ajax()
function to make a service call that updates some values in the database. It runs fine on localhost, but on the actual server I get a 500 Internal Server Error in the console window.
My client-side code is as below:
var param = FunctionToMakeKeyValueString();
$.ajax({
type: "POST",
url: "../Helpers/Autoplete.asmx/OrderStatements",
data: { param: param },
clientType: "application/json; charset=utf-8",
datatype: "json",
async: true,
success: function () { ShowSuccess();},
error: function () { ShowError(); }
});
And server-side code is:
[WebService(Namespace = "http://tempuri/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, unment the following line.
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService {
public AutoComplete () {
//Unment the following line if using designed ponents
//InitializeComponent();
}
[WebMethod]
public void OrderStatements(string param)
{
IneStatementService service = new IneStatementService();
string[] ps = param.Split(';');
foreach (string s in ps)
{
int id;
short order;
string[] pieces = s.Split(':');
if (int.TryParse(pieces[0], out id) && short.TryParse(pieces[1], out order))
{
IneStatement statement = service.FindBy(id);
statement.Order = order;
service.UpdateOrder(statement);
}
}
}
}
the actual asmx file is just
<%@ WebService Language="C#" CodeBehind="~/App_Code/AutoComplete.cs" Class="AutoComplete" %>
I'm sure the url is correct (the .js file is in a sibling folder to Helpers, which contains the asmx), but is there something else that I need to set in IIS or the web.config file? Thanks!
Share Improve this question asked Oct 25, 2013 at 23:33 BrettBrett 1,2871 gold badge13 silver badges22 bronze badges 1- 4 500 is a server error. Look at the server logs - they should tell you what is happening. – user1864610 Commented Oct 25, 2013 at 23:36
3 Answers
Reset to default 2Comment by @Mike W led me to look into the server error logs a bit, where I found:
Exception type: InvalidOperationException
Exception message: Request format is unrecognized for URL unexpectedly ending in '/OrderStatements'.
I googled that message which let me to this stack overflow question and it seems like it was as simple as adding this to the systen.web section of my config file:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
Can you Try adding below line into your web.config httpHandlers
<system.web>
<httpHandlers>
<add verb="*" path="*.asmx" type="System.Web.Services.Protocols.WebServiceHandlerFactory, System.Web.Services" />
</httpHandlers>
</system.web>
There Might be a problem with the Host link You have provided in JavaScript/Jquery
Please take a note down If you are looking this at chrome clear the browser data and you will see same result at both ends
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745134011a4613111.html
评论列表(0条)