使用带有证书的https上的WSDL服务

时间:2012-03-14 08:08:38

标签: wcf soap wsdl certificate

我有相同的wsdl服务,我在VS中连接, 我从服务管理员那里收到的证书 和https地址连接。 所以,我需要从这个wsdl服务(MigomCommonService)中调用一个方法,这是我的代码:

            string adress = "https://xxxx.xxx.com/MigomCommonService/MigomCommonPort";
            string thumbprint = "xx xx xx xx xx xx xx xx xx xx xx xx xx xx";

            WSHttpBinding binding = new WSHttpBinding();
            binding.Name = "MigomCommonBinding";
            binding.Security.Mode = SecurityMode.Transport;
            binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;

            EndpointAddress addr = new EndpointAddress(adress);

            MigomCommonService.MigomCommonPortTypeClient migomClient = new MigomCommonService.MigomCommonPortTypeClient(binding, addr);
            migomClient.ClientCredentials.ClientCertificate.Certificate = GetCertificate(thumbprint);

            migomClient.Open();

            Session sessionPart = SessionPartRequest();
            string requestPart = CountryListRequest();
            string response = migomClient.MigomCommonOperation(ref sessionPart, requestPart);

当我调用MigomCommonOperation方法时,我遇到了身份验证错误(407),但我可以通过浏览器成功调用此wsdl服务。 这段代码有什么问题?也许我忘记了约束部分或其他事情?

1 个答案:

答案 0 :(得分:0)

我想这个链接可以解决您的问题。通过HTTPS协议访问WCF端点。 http://www.codeproject.com/Articles/36705/7-simple-steps-to-enable-HTTPS-on-WCF-WsHttp-bindi 您需要将证书安装到本地并信任它,然后配置WCF servicepointmanager,如:

ServicePointManager.ServerCertificateValidationCallback = 
          new RemoteCertificateValidationCallback(IgnoreCertificateErrorHandler); 
        Service1Client obj = new Service1Client();