Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add service reference gives Exception: Unable to connect to remote server

My WCF service returns result when calling from console application client. However, it's showing

Exception: Unable to connect to remote server

Actual Error:

Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.

Error details:

The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.

Server stack trace: at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter) at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at IJiraService.GetProjects() at JiraServiceClient.GetProjects()

Please note that, when Fiddler is running, the service is working fine.However, if I close Fiddler, then it shows exception:

This is Fiddler log(while I'm getting the data):

TTP/1.1 200 Connection Established Date: Thu, 06 Aug 2015 14:39:22 GMT Proxy-Connection: Keep-Alive Via: 1.1 localhost.localdomain

Encrypted HTTPS traffic flows through this CONNECT tunnel. HTTPS Decryption is enabled in Fiddler, so decrypted sessions running in this tunnel will be shown in the Web Sessions list.

Secure Protocol: Tls Cipher: Aes128 128bits Hash Algorithm: Sha1 160bits Key Exchange: ECDHE_RSA (0xae06) 256bits

== Server Certificate ========== [Subject] CN=*.atlassian.net, O="Atlassian Network Services, Inc.", L=San Francisco, S=California, C=US

[Issuer] CN=DigiCert SHA2 High Assurance Server CA, OU=www.digicert.com, O=DigiCert Inc, C=US

[Serial Number] 08E828A2F8C521A2DC7121A28E191837

[Not Before] 9/9/2014 5:30:00 AM

[Not After] 11/15/2017 5:30:00 PM

[Thumbprint] EA57BE3C6CDA33E6D875889944EE61284E39D91D


HTTP/1.1 200 OK Server: nginx Date: Thu, 06 Aug 2015 14:39:26 GMT Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive Vary: Accept-Encoding X-AREQUESTID: 39x4118x1 X-ASEN: SEN-2425233 Set-Cookie: JSESSIONID=8B68E46928883CA9F99382A67C228541; Path=/; Secure; HttpOnly Set-Cookie: studio.crowd.tokenkey=""; Domain=.clientname.atlassian.net; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; Secure; HttpOnly X-Seraph-LoginReason: OUT Set-Cookie: studio.crowd.tokenkey=YcO0N1IItmmGYah6bzgN0w00; Domain=.clientname.atlassian.net; Path=/; Secure; HttpOnly X-Seraph-LoginReason: OK Set-Cookie: atlassian.xsrf.token=ALMX-0SVV-VVCK-3Y73|c420e5bfab5c997ccdfa21ffa129d60a69af0013|lin; Path=/; Secure X-ASESSIONID: b2v6it X-AUSERNAME: admin X-ATENANT-ID: clientname.atlassian.net Cache-Control: no-cache, no-store, no-transform X-Content-Type-Options: nosniff Strict-Transport-Security: max-age=315360000;includeSubDomains

As per above Fiddler log is Something I must change in web.config file to make it work?

when called from WCF test client. Here is what I have tried:

Web.config:

<?xml version="1.0"?>
  <configuration>
  <!--<system.net>
   <defaultProxy useDefaultCredentials="true" >
  </defaultProxy>
 </system.net>-->
<appSettings>
<add key="UserName" value="admin"/>
<add key="Password" value="admin"/>
<add key="resturl" value="https://Clientname.atlassian.net/rest/api/2/"/>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
 <system.web>
  <compilation debug="true" targetFramework="4.5" />
  <httpRuntime targetFramework="4.5"/>
 </system.web>
 <system.serviceModel>
  <bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IJiraService"/>
    </basicHttpBinding>
    </bindings>
   <client>
     <endpoint address="http://localhost:19065/JiraService.svc"  binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IJiraService" contract="ServiceReference1.IJiraService"
       name="BasicHttpBinding_IJiraService" />
    </client>
    <behaviors>
     <serviceBehaviors>
       <behavior>
         <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
         <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
      <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
   </protocolMapping>    
   <serviceHostingEnvironment aspNetCompatibilityEnabled="true"   multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
   <!--
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
  -->
  <directoryBrowse enabled="true"/>
 </system.webServer>

</configuration>

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()
 {
       HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
        // HttpClient 


        request.ContentType = "application/json; charset=UTF-8";
        //request.ContentType = "text/xml; charset=UTF-8";
        /*request.Headers.Add("X-Atlassian-Token", "nocheck");
        request.UseDefaultCredentials = true;
        request.KeepAlive = true;*/
        request.Method = method;

        /*if (data != null)
        {
            using (StreamWriter writer = new StreamWriter(request.GetRequestStream(),Encoding.ASCII))
            {
                writer.Write(data);
            }
        }*/
        string base64Credentials = GetEncodedCredentials();
        request.Headers.Add("Authorization", "Basic " + base64Credentials);



     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 debugging by invoking 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", it's working fine. However, when I add as "Add service reference" in the same console application, it's 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?

like image 772
AskMe Avatar asked Jul 23 '15 06:07

AskMe


1 Answers

Issue solved by adding proxy in IIS. :)

like image 89
AskMe Avatar answered Nov 10 '22 03:11

AskMe