0

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!!

user1192475
  • 47
  • 1
  • 11

2 Answers2

0

Change your URL to "http://sebtest.somee.com/page/webservice/PositionService.asmx/getLastLocation" and see if that works for you.

bschultz
  • 4,244
  • 1
  • 25
  • 33
0

I didn't really find an answer to my problems, but instead I used a different approach that is described here (http://www.codeproject.com/Articles/223572/Calling-Cross-Domain-WCF-service-using-Jquery-Java) and that works perfectly fine.

One last note of advice if you also consider using this approach, you may find it helpful to use this web.config configuration instaed of the described one:

<?xml version="1.0"?>
<configuration>

<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="None">
</authentication>
</system.web>
<system.serviceModel>

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<standardEndpoints>
  <webScriptEndpoint>
    <standardEndpoint name="" crossDomainScriptAccessEnabled="true"/>
  </webScriptEndpoint>
</standardEndpoints>

<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

user1192475
  • 47
  • 1
  • 11