I am trying to access a .Net Web service (.asmx) that I created and that runs under this location: http://sebtest.somee.com/page/webservice/PositionService.asmx
Invoking the service locally works fine, but consuming it with jQuery on the server fails unfortunatelly. The service is written in the following way:
namespace WcfService1
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// Below line allows the web service to be called through HTTP protocol.
[ScriptService]
public class ServiceImpl : System.Web.Services.WebService, IService1j
{
[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public PositionReturnType getLastLocation(){
.
.
I also created an asp.net web page that when started directly attempts to access the getLastLocation method. The page can be found here: http://sebtest.somee.com/page/
As you can see I only get an error.
The code of the web page is this one:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title>Call web service test</title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.min.js"></script>
<script type="text/javascript">
function CallService() {
$.ajax({
type: "POST",
url: "http://sebtest.somee.com/page/webservice/PositionService.asmx?op=getLastLocation",
dataType: "json",
success: function (data, textStatus, jqXHR) {
alert('worked');
},
error: function (jqXHR, textStatus, errorThrown) {
alert(jqXHR + ' - ' + textStatus + ' - ' + errorThrown);
}
});
}
</script>
</head>
<body onload="CallService()">
<form runat="server">
What I realized is that most examples use the URL form "Service/Methodname" which my service doesn't reply to. Instead the method can be viewed under the location sebtest.somee.com/page/webservice/PositionService.asmx?op=getLastLocation Could that be a problem of some sort?
I would be glad for any help you can provide me! Maybe you could give me an example calling my service.
Thanks a lot in advance for your help :)
Sebastian
Edit: I realized now that I can open the webservice manually to HTTP Get and HTTP Post requests by changing the web.config file. I did this and I tried to access the webservice now from a web page running locally on my desktop in the following way:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
function CallService() {
$.ajax({
type: "GET",
url: "http://sebtest.somee.com/page/webservice/PositionService.asmx/getLastLocation?",
dataType: "xml",
error: function (xhr, textStatus, errorThrown) {
alert('nooo ' + xhr + ' - ' + textStatus + ' - ' + errorThrown);
},
success: function (data, textStatus, jqXHR) {
alert('jaaa ' + data + " - " + textStatus + " - " + jqXHR);
}
});
}
Unfortunatelly this still leads to the error function to be called. In chrome no error text is displayed, IE says "No transport". However, I also used Fiddler2 and there I get the following response which is exactly what I need:
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 07 Feb 2012 13:06:37 GMT
Content-Length: 266
<?xml version="1.0" encoding="utf-8"?>
<PositionReturnType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<longtitude>3</longtitude>
<latitude>9</latitude>
</PositionReturnType>
Maybe this can help you figuring out my problem? I mean obviously the data are returned correctly as expected to my desktop pc but the error function is called instead of the success one.
Thanks!!