Reputation: 381
i am running asmx service in one port localhost:5739 and trying to call the service from other port or plain html + jquery out of the project
but i am unable to access the web service
my webservice is
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string HelloWorld(string text) {
return "Hello World" + text;
}
and my code to invoke webservice is
$.ajax(
{
type: "POST",
url: "http://localhost:5739/asmxservices/testservice.asmx/HelloWorld",
data: '{ "text": "Kartheek"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
error: OnError
});
function OnSuccess(data, status) {
alert(data.d);
};
function OnError(msg) {
alert('error = ' + msg.d);
}
Upvotes: 0
Views: 2684
Reputation: 629
The following Steps solved my problem, hope it helps some one,
[System.Web.Script.Services.ScriptService] public class GetData : System.Web.Services.WebService {
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
Upvotes: 0
Reputation: 1
It seems that your trouble caused by file placement. JS code calling your service shold be on the same host as your service. Just put html file at your project root folder and try to run it from the directory listing while debug. As sample: I test service calling file with path
http://localhost:51169/2.html
Upvotes: 0
Reputation: 14672
Your method needs to be static, like this:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string HelloWorld(string text) {
return "Hello World" + text;
}
Upvotes: 1