c# – 添加服务引用异常:无法连接到远程服务器
从控制台应用程序客户端调用时,我的WCF服务返回结果.但是,它显示
实际错误:
错误详情:
请注意,当Fiddler正在运行时,该服务正常工作.但是,如果我关闭Fiddler,则会显示异常: 这是Fiddler日志(当我得到数据时): TTP / 1.1 200连接建立 加密的HTTPS流量流经此CONNECT隧道.在Fiddler中启用HTTPS解密,因此在此隧道中运行的解密会话将显示在“Web会话”列表中. 安全协议:Tls ==服务器证书========== [发行者] [序列号] [不在之前] [不后] [指纹] HTTP / 1.1 200 OK 根据以上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(); } 注意:“方法”从“GetProjects”中被调用 这是通过调用WCF测试客户端调试时得到的内部异常: 这是我内心的异常
注意:当我从控制台应用程序进行调试时,没有调试异常.正如我所说,控制台应用程序正常工作,我可以从服务返回结果. 更新:当我在控制台应用程序中添加这个服务作为“添加引用”时,它的工作正常.但是,当我在同一个控制台应用程序中添加为“添加服务引用”时,它显示同样的错误.我的网络是阻止某些东西吗?请帮忙. 如何纠正?还有什么我需要添加到web.config中吗?或者我需要允许URL作为受信任的URL吗? 解决方法
通过在IIS中添加代理解决问题. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |