I have created a WCF REST style service in my project. In development I am able to specify the relative url to access my service,
jQuery.ajax({
url: "/WebServices/AddressWebService.svc/GetCountry",
datatype: "json",
success: function (data) {
jQuery.each(data.GetCountryResult, function (index, value) {
//value.entityData.CountryGuid
//value.entityData.CountryName
$('#dataCountry').empty();
$('#dataCountry').append('<option value="' + value.entityData.CountryGuid + '">' + value.entityData.CountryName + '</option>');
});
}
});
When I hosted to IIS (with port 81), with the root folder name c2c, I am no longer able to access the service
Using fire bug, I tried to see the headers, my relative url (“/WebServices/AddressWebService.svc/GetCountry) gets appended to my host (localhost:81) but the virtual folder name (c2c) is not getting appended. As a result it shows file not found exception
If I use the full qualified url (http://localhost:81/c2c/WebServices/AddressWebService.svc/GetCountry), it works fine.
If I am using full qualified url, It will be difficult to do changes when moving to production. Although we can use global variables to store the webroot (in this case c2c)
Are there any simple solution to solve this problem, I have also given the base address in the config file
<system.serviceModel>
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="c2c.WebServices.AddressWebService" behaviorConfiguration="jsonBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:81/c2c"/>
</baseAddresses>
</host>
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webmax" contract="c2c.WebServices.IAddressWebService" behaviorConfiguration="jsonendpointBehavior" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
You need to get a relative URL to the call to the
ajaxmethod. Typically what I do is(obviously, you’d need the rest of the params to be set, and this would have to be on an ASP .NET control (like a page)).
However, if you’re not spitting out the JavaScript on the page, that won’t work. In that case, you’ll want to pass in the URL of your web service to a JavaScript object or namespace, which is defined in the JavaScript include file. So you might have something like this:
where you define the
MyServiceMethodCallernamespace in your JavaScript include file. That way, inside your include file, you could have:I think this should work. I haven’t brought it up in a tested, workable example, but you get the gist of it.