My WCF service returns result when calling from Console application client. However, its showing "Exception: Unable to connect to remote server " when called from WCF test client. Here is what I have tried:
Web.config
<appSettings>
<add key="MyUserName" value="admin"/>
<add key="MyPassword" value="admin"/>
<add key="resturl" value="http://ift.tt/1LEQkmJ"/>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
Here is how I'm requesting in my code:
public class Service : IService
{
private string GetRestURL()
{
return System.Configuration.ConfigurationManager.AppSettings["resturl"];
}
private string GetUserName()
{
return System.Configuration.ConfigurationManager.AppSettings["MyUserName"];
}
private string GetPassword()
{
return System.Configuration.ConfigurationManager.AppSettings["MyPassword"];
}
public string method()
{
string url = string.Format("{0}{1}", GetRestURL(), "project");
///////////////////////////////////////////
Here is my HTTP request goes
///////////////////////////////////////////
string base64Credentials = GetEncodedCredentials();//this will read my credential from config.
try
{
request.Headers.Add("Authorization", "Basic " + base64Credentials);
response = request.GetResponse() as HttpWebResponse; //here its NULL
if (response.StatusCode != HttpStatusCode.OK)
{
throw new Exception(String.Format("Server error (HTTP {0}:{1}).",response.StatusCode,response.StatusDescription));
}
}
catch (Exception ex) //Here I'm getting exception
{
throw new Exception(ex.Message);
}
}
}
here is my method signature:
[ServiceContract]
public interface IService
{
[OperationContract]
List<ProjectDescription> GetProjects();
}
Note: the "method" is getting called from "GetProjects"
This is the inner exception I'm getting when dedugging by invokeing WCF test client:
This is I'm getting inner exception
"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 165.254.xxx.xxx:443"
NOTE: There is no debug exception when I'm debugging from console application. as I said, console application is working fine and I'm able to return the result from the service.
UPDATE: When I'm adding this service in console application as "Add reference" , its working fine. However, when I add as "Add service reference" in the same console application, its showing me same error.Is it my web is blocking something? Please help.
How to correct this? Is there something else I need to add in web.config? OR do I need to allow the URL as trusted URL somewhere?
Aucun commentaire:
Enregistrer un commentaire