添加服务引用给出了异常:无法连接到远程服务器 [英] Add service reference gives Exception: Unable to connect to remote server

查看:3021
本文介绍了添加服务引用给出了异常:无法连接到远程服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WCF服务返回结果。然而,它显示

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

异常:无法连接到远程服务器

Exception: Unable to connect to remote server

实际误差:

无法调用服务。可能的原因:该服务处于脱机状态或无法访问;客户端配置不匹配   代理;现有的代理是无效的。请参考堆栈跟踪   更多的细节。您可以尝试通过启动一个新的代理来恢复,恢复   默认配置,或刷新该服务。

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.

错误的详细信息:

服务器无法处理请求由于内部错误。   有关错误的详细信息,无论是打开   IncludeExceptionDetailInFaults(无论是从ServiceBehaviorAttribute   或从配置行为)在服务器上   为了发送异常信息返回给客户端,或打开   跟踪按照微软.NET Framework SDK文档和   检查服务器跟踪日志。

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.

服务器堆栈跟踪:在   System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(消息   回复,MessageFault故障,串动,MessageVersion版本,   FaultConverter faultConverter)在   System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime   操作,ProxyRpc和放大器; RPC)在   System.ServiceModel.Channels.ServiceChannel.Call(串动,   布尔单向,ProxyOperationRuntime操作,对象[]插件,   在[对象]出局,时间跨度超时)   System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage   methodCall,ProxyOperationRuntime操作)的   System.ServiceModel.Channels.ServiceChannelProxy.Invoke(即时聊天   消息)

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)

例外重新抛出的[0]:在   System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天   reqMsg,即时聊天retMsg)在   System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&安培;   MSGDATA,的Int32型)在IJiraService.GetProjects()在   JiraServiceClient.GetProjects()

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()

请注意,当小提琴手正在运行,服务工作fine.However,如果我关闭小提琴手,那么就说明例外:

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已建立连接 日期:星期四,2015年8月6日14时39分二十二秒GMT - 代理连接:保持活动 途经:1.1的localhost.localdomain

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

加密的HTTPS流量通过此连接隧道。 HTTPS解密在提琴手启用,在这条隧道运行,这样解密的会议将显示在Web会话列表中。

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.

安全协议:TLS 密码:AES128 128位 哈希算法:SHA1 160bits 密钥交换:ECDHE_RSA(0xae06)的256

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

==服务器证书========== [学科]   CN = * atlassian.net,O =Atlassian的网络服务公司,L =旧金山,S =加州,C = US

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

[发行]   CN = DigiCert SHA2高保证服务器CA,OU = www.digicert.com,O = DigiCert公司,C = US

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

[序号]   08E828A2F8C521A2DC7121A28E191837

[Serial Number] 08E828A2F8C521A2DC7121A28E191837

[不前]   2014年9月9日上午5时30分00秒

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

[不经过]   二零一七年十一月十五日下午5点30分○○秒

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

[指纹]   EA57BE3C6CDA33E6D875889944EE61284E39D91D

[Thumbprint] EA57BE3C6CDA33E6D875889944EE61284E39D91D

HTTP / 1.1 200 OK 服务器:nginx 日期:星期四,2015年8月6日14时39分26秒格林尼治标准​​时间 内容类型:应用程序/ JSON;字符集= UTF-8 传输编码:分块 连接:保持活动 有所不同:接受编码 的X AREQUESTID:39x4118x1 的X日月:SEN-2425233 设置Cookie:JSESSIONID = 8B68E46928883CA9F99382A67C228541;路径= /;安全;仅Http 设置Cookie:studio.crowd.tokenkey =;域名= .clientname.atlassian.net;过期=周四,01月 - 1970年00:00:10 GMT;路径= /;安全;仅Http 的X六翼天使,LoginReason:OUT 设置Cookie:studio.crowd.tokenkey = YcO0N1IItmmGYah6bzgN0w00;域名= .clientname.atlassian.net;路径= /;安全;仅Http 的X六翼天使,LoginReason:OK 设置Cookie:atlassian.xsrf.token = ALMX-0SVV-VVCK-3Y73 | c420e5bfab5c997ccdfa21ffa129d60a69af0013 |林;路径= /;安全 的X ASESSIONID:b2v6it 的X AUSERNAME:管理员 的X ATENANT-ID:clientname.atlassian.net 缓存控制:无缓存,无店面,无转换 的X内容类型选项:nosniff 严格,运输和安全性:最大年龄= 315360000; includeSubDomains

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

按照上面的提琴手日志是我必须在web.config文件修改,使其工作?

从WCF测试客户端调用时。以下是我曾尝试:

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

Web.config文件:

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>

下面是如何,我要求我的code:

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);
    }
 }

下面是我的方法签名:

[ServiceContract]
public interface IService
{
    [OperationContract]
    List<ProjectDescription> GetProjects();
 }

注:该办法是越来越从GetProjects名为

Note: the "method" is getting called from "GetProjects"

这是内部异常我通过调用WCF测试客户端调试的时候获得:

This is the inner exception I'm getting when debugging by invoking WCF test client:

这是我收到内部异常

一个连接尝试失败,因为连接的方没有在一段时间后正确响应或已建立的连接失败,因为连接主机未能响应165.254.xxx.xxx:443

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.

如何纠正呢?有没有别的东西,我需要在的web.config 补充的吗?或者我需要让作为地方值得信赖的URL网址?

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?

推荐答案

问题在IIS中加入代理解决。 :)

Issue solved by adding proxy in IIS. :)

这篇关于添加服务引用给出了异常:无法连接到远程服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆