从控制台应用程序客户端调用时,我的WCF服务返回结果。但是,它显示了
例外:无法连接到远程服务器
实际错误:
无法调用该服务。可能的原因:服务离线或无法访问;客户端配置不匹配 代理人;现有代理无效。请参阅堆栈跟踪 更多详情。您可以尝试通过启动新代理进行恢复,然后进行恢复 默认配置或刷新服务。
错误详情:
由于内部错误,服务器无法处理请求。 有关错误的更多信息,请打开 IncludeExceptionDetailInFaults(来自ServiceBehaviorAttribute 或者来自服务器上的配置行为) 命令将异常信息发送回客户端,或打开 根据Microsoft .NET Framework SDK文档进行跟踪 检查服务器跟踪日志。
服务器堆栈跟踪:at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(消息 回复,MessageFault错误,字符串操作,MessageVersion版本, FaultConverter faultConverter)at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime 操作,ProxyRpc& rpc)at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway,ProxyOperationRuntime操作,Object [] ins, 对象[]出局,TimeSpan超时)at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime operation)at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(即时聊天 消息)
在[0]处重新抛出异常:at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天 reqMsg,IMessage retMsg)at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&安培; msgData,Int32类型)在IJiraService.GetProjects()处 JiraServiceClient.GetProjects()
请注意,当Fiddler正在运行时,该服务正常运行。但是,如果我关闭Fiddler,则会显示异常:
这是Fiddler日志(我获取数据的时候):
TTP / 1.1 200建立连接 日期:2015年8月6日星期四14:39:22 GMT 代理连接:保持活跃 通过:1.1 localhost.localdomain
加密的HTTPS流量流经此CONNECT隧道。在Fiddler中启用了HTTPS解密,因此在此隧道中运行的解密会话将显示在Web会话列表中。
安全协议:Tls 密码:Aes128 128bits 散列算法:Sha1 160bits 密钥交换:ECDHE_RSA(0xae06)256bits
==服务器证书========== [学科] 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 Inc,C = US
[序列号] 08E828A2F8C521A2DC7121A28E191837
[不在之前] 9/9/2014 5:30:00 AM
[不在之后] 11/15/2017 5:30:00 PM
[指纹] EA57BE3C6CDA33E6D875889944EE61284E39D91D
HTTP / 1.1 200好的 服务器:nginx 日期:星期四,2015年8月6日14:39:26 GMT Content-Type:application / json; charset = UTF-8 转移编码:分块 连接:保持活力 变化:接受编码 X-AREQUESTID:39x4118x1 X-ASEN:SEN-2425233 Set-Cookie:JSESSIONID = 8B68E46928883CA9F99382A67C228541;路径= /;安全;仅Http Set-Cookie:studio.crowd.tokenkey ="&#34 ;;域= .clientname.atlassian.net; Expires = Thu,01-Jan-1970 00:00:10 GMT;路径= /;安全;仅Http X-Seraph-LoginReason:OUT Set-Cookie:studio.crowd.tokenkey = YcO0N1IItmmGYah6bzgN0w00;域= .clientname.atlassian.net;路径= /;安全;仅Http X-Seraph-LoginReason:好的 Set-Cookie:atlassian.xsrf.token = ALMX-0SVV-VVCK-3Y73 | c420e5bfab5c997ccdfa21ffa129d60a69af0013 | lin;路径= /;安全 X-ASESSIONID:b2v6it X-AUSERNAME:管理员 X-ATENANT-ID:clientname.atlassian.net 缓存控制:无缓存,无存储,无变换 X-Content-Type-Options:nosniff 严格传输安全:max-age = 315360000; includeSubDomains
如上所述Fiddler日志是我必须在web.config文件中更改的内容才能使其正常工作?
从WCF测试客户端调用时。这是我尝试过的:
的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>
以下是我在代码中请求的方式:
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();
}
注意:&#34;方法&#34;正在从&#34; GetProjects&#34;
调用这是我通过调用WCF测试客户端进行调试时得到的内部异常:
这是我得到内部异常
连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应165.254.xxx.xxx:443
注意:从控制台应用程序调试时没有调试异常。正如我所说,控制台应用程序工作正常,我能够从服务中返回结果。
更新:当我在控制台应用程序中添加此服务作为&#34;添加引用&#34;时,它正常工作。但是,当我添加&#34;添加服务参考&#34;在同一个控制台应用程序中,它显示了同样的错误。我的网络阻止了什么吗?请帮忙。
如何纠正?我需要在web.config
添加其他内容吗?或者我是否需要在某个地方允许URL作为可信URL?
答案 0 :(得分:1)
通过在IIS中添加代理解决了问题。 :)
答案 1 :(得分:0)
你试过这个答案吗?听起来它解决了您遇到的问题:
答案 2 :(得分:0)
尝试调整HTTPS的绑定,并确保也为http配置。
<protocolMapping>
<!--<add binding="basicHttpBinding" scheme="http"/>-->
<add binding="basicHttpsBinding" scheme="https"/>
<add binding="webHttpBinding" scheme="https" bindingConfiguration="WebBinding"/>
</protocolMapping>