wcf - 从 WCF 调用 HTTPS REST 服务

标签 wcf https

我需要通过 HTTPS 从第三方服务器调用一些 REST 服务。我的想法是,我将为自己创建一个不错的小型 WCF 库来处理这些调用并反序列化响应。不过,我有点不高兴了。

我试图调用的服务有一个简单地响应 OK 的测试服务。

我在界面中创建了一个 OperationContract,如下所示:

[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Bare,
    ResponseFormat = WebMessageFormat.Xml,
    UriTemplate = "test")]
 string Test();

在我的服务代码中,我有一个公共(public)方法如下:
public string Test()
{
    ChannelFactory<IService1> factory = new ChannelFactory<IService1>("UMS");
    var proxy = factory.CreateChannel();
    var response = proxy.Test();
    ((IDisposable)proxy).Dispose();
    return (string)response;
}

我的 app.config 看起来像这样:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <system.serviceModel>
    <client>
      <endpoint address="https://61.61.34.19/serv/ums/"
              binding="webHttpBinding"
              behaviorConfiguration="ums"
              contract="WCFTest.IService1"
              bindingConfiguration="webBinding"
              name="UMS" />
    </client>
    <services>
      <service name="WCFTest.Service1" behaviorConfiguration="WCFTest.Service1Behavior">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8731/Design_Time_Addresses/WCFTest/Service1/" />
          </baseAddresses>
        </host>
        <endpoint address ="" binding="wsHttpBinding" contract="WCFTest.IService1">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="ums">
          <clientCredentials>
            <clientCertificate findValue="restapi.ext-ags.801" 
                               storeLocation="CurrentUser" 
                               x509FindType="FindBySubjectName"/>
          </clientCredentials>
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="WCFTest.Service1Behavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>       
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>
        <binding name="webBinding">
          <security mode="Transport">
            <transport clientCredentialType="Certificate" proxyCredentialType="None"/>
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

我尝试调用测试方法,但收到错误“无法为具有权限‘61.61.34.19’的 SSL/TLS 安全 channel 建立信任关系。”

谁能看到我在这里缺少的东西?

任何帮助表示赞赏。干杯。

最佳答案

Could not establish trust relationship for the SSL/TLS secure channel with authority '61.61.34.19'.



这通常意味着服务器的 SSL 证书存在问题。是自签的吗?如果是这样,您必须为证书建立信任,通常通过 trusting the issuing CA or installing the cert in the windows cert store .

关于wcf - 从 WCF 调用 HTTPS REST 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8579077/

相关文章:

asp.net - 将 aspNetCompatibilityEnabled 设置为 true 会在基于 REST 的 JSON WCF 服务中抛出 MethodAccessException

java - 在Java中使用WCF服务

c# - 实体太大错误

java - 安装 SSL 证书后,Glassfish 对 HTTPS 没有响应

javascript - 使函数在 HTTP 和 HTTPS 中工作

api - WSO2 ESB : HTTPS API

.net - 如何使WCF服务STA(单线程)

php - PHP SoapClient 调用中的空值

asp.net-mvc-3 - 正确响应仅 HTTPS 站点上的 HTTP HEAD 请求

javascript - 我可以使用 TLS 加密 Node.js TCP 流量以使其无法读取吗?