我需要通过HTTPS从第三方服务器调用一些REST服务。我的想法是,我会创建一个漂亮的小WCF库来处理这些调用并反序列化响应。我虽然有点不知所措。
我试图呼叫的服务有一个测试服务,只需响应就可以了。
我在界面中创建了一个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>
我尝试调用测试方法,但收到错误“无法为具有权限的SSL / TLS安全通道建立信任关系'61 .61.34.19'。”
谁能看到我在这里缺少的东西?
任何帮助表示赞赏。欢呼声。
答案 0 :(得分:1)
无法与权限为'61 .61.34.19'的SSL / TLS安全通道建立信任关系。
这通常意味着服务器的SSL证书存在问题。它是自签名的吗?如果是这样,您必须通过trusting the issuing CA or installing the cert in the windows cert store建立对证书的信任。
答案 1 :(得分:0)
尝试将webHttpBinding安全设置从“传输”更改为“无”。