2011-12-20 90 views
3

我需要通过HTTPS从第三方服务器调用一些REST服务。我的想法是,我会自己创建一个漂亮的小WCF库来处理这些调用并对反应进行反序列化。尽管如此,我还是会有些失落。从WCF调用HTTPS REST服务

我试图调用的服务有一个测试服务,只是回应OK。

我已经创建了我的界面中的OperationContract的,如下图所示:

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

在我的服务代码,下面我有一个公共方法:

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> 

我尝试调用测试方法,但收到错误“无法建立信任关系nship为SSL/TLS安全通道,授权为'61 .61.34.19'。“

任何人都可以看到我在这里失踪?

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

+0

你可以从你的IE浏览到REST服务,看到回应?客户端认证是否由REST服务使用客户端证书完成? – Rajesh 2011-12-21 09:51:51

+0

是Rajesh,我可以从IE浏览并查看响应。 – 2011-12-21 10:27:05

+0

如果您的证书是自签名的,那么您是否实施了验证服务器证书的ServicePointManager回调方法。您是否也正在从您尝试测试的客户端机器浏览服务? – Rajesh 2011-12-21 10:33:14

回答

1

无法为权限为'61 .61.34.19'的SSL/TLS安全通道建立信任关系。

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

+0

Cheers Randolph,证书安装在商店中,如果我点击测试服务的URI在IE中我可以看到结果,只是努力从WCF执行相同的操作。还尝试通过询问cert store直接从bog标准WPF应用程序调用,找到证书并添加到HttpWebRequest.CientCertificates集合,然后调用.GetResponse()作为HttpWebResponse – 2011-12-21 09:28:42

0

尝试将webHttpBinding安全设置从“传输”更改为“无”。