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>
<behaviors>
<serviceBehaviors>
<behavior name="jsonBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="jsonendpointBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding maxReceivedMessageSize="4194304" name="webmax">
</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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
</system.serviceModel>