I have an asp.net webforms website and a wcf service. I use jQuery to perform my AJAX operations to/from the WCF service like so:
$.ajax({
type: "POST",
url: "192.168.1.24/ServiceMain.svc/" + serviceName,
dataType: "json",
contentType: "application/json; charset=utf-8",
data: "{}",
cache: true,
success: function (json)
{
//Success operation here
},
error: function ()
{
//Error operation here
}
});
All is fine right now. However, I want to be able to do a testing and production environment, both of which will be hosted on a different server with different IP Addresses.
Clearly, hard-coding the URL to point to the correct WCF service will become a tedious problem if left unchecked. Therefore, I was wondering what was the best approach in retrieving the WCF Service’s URL. I thought about using the web.config file with something like the following:
<%=ConfigurationManager.AppSettings("SomeWCFKey")%>
However, I am not sure how to correctly reference the address in my web.config file:
<endpoint address="http://192.168.1.24/ServiceMain.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IServiceMain"
contract="ServiceMain.IServiceMain"
name="BasicHttpBinding_IServiceMain" />
Any help would be appreciated, thanks.
Hi i think you are actully want to read endpoint address that you can get by this code
Here is pont that descirpt mroe in detail : Getting WCF Bindings and Behaviors from any config source
this might also help you : Programmatically enumerate WCF endpoints defined in app.config