【发布时间】:2011-08-04 16:31:56
【问题描述】:
我是 .NET 和 SSL 的新手,我面临着在 SOAP 服务和客户端之间建立安全通信的问题。 它在 HTTP 上运行良好,但现在我们必须应用 SSL。 我们从 CA 获得证书。 接下来的步骤如下:
1) 使用httpcfg set ssl -i 0.0.0.0:777 -h <thumbprintkey>启用服务使用的端口
2)httpcfg set urlacl -u @987654321@ -a D:(A;;GA;;;AN)
3)httpcfg set iplisten-i 0.0.0.0:777
WebService 代码如下:
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Message.ClientCredentialType = MessageCredentialType.None;
ServiceHost host = new ServiceHost(typeof(DeviceObservationConsumer_hostPCDData), new Uri("https://<domainname>:777/TlsService/ServiceSecure"));
host.Credentials.ServiceCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindByThumbprint, (string)"bd 35 ec c0 e6 b3 9a ac 74 09 09 c5 84 b8 fd 58 51 44 87 7d");
host.AddServiceEndpoint(typeof(IDeviceObservationConsumer_Binding_Soap12), binding, "");
ServiceMetadataBehavior smb = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
// If not, add one
if (smb == null)
smb = new ServiceMetadataBehavior();
smb.HttpsGetEnabled = true;
host.Description.Behaviors.Add(smb);
// Add MEX endpoint
host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpsBinding(), "mex");
host.Open();
客户端代码如下:
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Message.ClientCredentialType = MessageCredentialType.None;
EndpointAddress addr = new EndpointAddress("https://<domainname>:777/TlsService/ServiceSecure");
ChannelFactory<DeviceObservationConsumer_PortType> myChannelFactory = new ChannelFactory<DeviceObservationConsumer_PortType>(binding, addr);
//myChannelFactory.Credentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindByThumbprint, (string)"bd 35 ec c0 e6 b3 9a ac 74 09 09 c5 84 b8 fd 58 51 44 87 7d");
DeviceObservationConsumer_PortType client = myChannelFactory.CreateChannel();
CommunicatePCDDataRequest req = new CommunicatePCDDataRequest("ciao mamma guarda come mi diverto!");
CommunicatePCDDataResponse resp = client.CommunicatePCDData(req);
myChannelFactory.Close();
服务和客户端都在同一台电脑上。
我无法通过浏览器访问https://<domanname>:777/TlsService/ServiceSecure(获取未找到页面错误),并且客户端肯定也无法访问它。
哪位大神能帮帮我!!!!??
提前致谢,
刘德米拉
【问题讨论】: