Ajax调用WCF窗口通过SSL服务(HTTPS) [英] Ajax call to wcf windows service over ssl (https)

查看:509
本文介绍了Ajax调用WCF窗口通过SSL服务(HTTPS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个窗口服务,它暴露了一个端点通过HTTP。再次,这是一个Windows服务(未托管在IIS的Web服务)。然后调用方法从这个端点,使用JavaScript / AJAX。一切完美的作品,这在code,我用我的Windows服务来创建端点:

I have a windows service which exposes an endpoint over http. Again this is a windows service (not a web service hosted in iis). I then call methods from this endpoint, using javascript/ajax. Everything works perfectly, and this the code I'm using in my windows service to create the endpoint:

        //Create host object
        WebServiceHost webServiceHost = new WebServiceHost(svcHost.obj, new Uri("http://192.168.0.100:1213"));

        //Add Https Endpoint
        WebHttpBinding binding = new WebHttpBinding();
        webServiceHost.AddServiceEndpoint(svcHost.serviceContract, binding, string.Empty);


        //Add MEX Behaivor and EndPoint
        ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior();
        metadataBehavior.HttpGetEnabled = true;
        webServiceHost.Description.Behaviors.Add(metadataBehavior);
        webServiceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");

        webServiceHost.Open();

现在,我的目标是让同样的工作模式通过SSL(HTTPS不是HTTP)。所以,我一直跟着几个MSDN页面的指导下,如下所示:

Now, my goal is to get this same model working over SSL (https not http). So, I have followed the guidance of several msdn pages, like the following:

http://msdn.microsoft.com/en -us /库/ ms733791(VS.100)的.aspx

我已经使用makecert.exe创建一个测试证书被称为bpCertTest。我已经然后用netsh.exe中配置我的端口(1213)与测试证书我创建的,都没有问题。然后,我如下修改端点code。在我的Windows服务才能够正常工作通过HTTPS:

I have used makecert.exe to create a test cert called "bpCertTest". I have then used netsh.exe to configure my port (1213) with the test cert I created, all with no problem. Then, I've modified the endpoint code in my windows service to be able to work over https as follows:

        //Create host object
        WebServiceHost webServiceHost = new WebServiceHost(svcHost.obj, new Uri("https://192.168.0.100:1213"));

        //Add Https Endpoint
        WebHttpBinding binding = new WebHttpBinding();
        binding.Security.Mode = WebHttpSecurityMode.Transport;
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
        webServiceHost.AddServiceEndpoint(svcHost.serviceContract, binding, string.Empty);
        webServiceHost.Credentials.ServiceCertificate.SetCertificate("CN=bpCertTest", StoreLocation.LocalMachine, StoreName.My);


        //Add MEX Behaivor and EndPoint
        ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior();
        metadataBehavior.HttpsGetEnabled = true;
        webServiceHost.Description.Behaviors.Add(metadataBehavior);
        webServiceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpsBinding(), "mex");

        webServiceHost.Open();

服务营造端点成功,认识我​​的证书在SetCertificate()调用,以及服务启动并成功运行。

The service creates the endpoint successfully, recognizes my cert in the SetCertificate() call, and the service starts up and running with success.

现在的问题是我的JavaScript / AJAX调用不能超过HTTPS服务进行通信。我只是得到了一些通用的commication错误(12031)。所以,作为一个测试,我改了口,我要求在JavaScript的一些其他的随机端口,我也得到了同样的错误 - 它告诉我,我显然即使没有达到我的服务通过https

Now, the problem is my javascript/ajax call cannot communicate with the service over https. I simply get some generic commication error (12031). So, as a test, I changed the port I was calling in the javascript to some other random port, and I get the same error - which tells me that I'm obviously not even reaching my service over https.

我在在这一点上完全丧失,我觉得一切都在的地方,我看不出有什么问题。如果任何人在这种情况下的经验,请提供您的见解和/或解决方案!

I'm at a complete loss at this point, I feel like everything is in place, and I just can't see what the problem is. If anyone has experience in this scenario, please provide your insight and/or solution!

谢谢!

推荐答案

我在这里有同样的问题。看来你不能AJAX调用到https做网页,而您的当前页面的HTTP。就像你不能做呼叫其他领域。这是违反SOP 的http:// code.google.com / P /谷歌网页工具包-DOC-1-5 /维基/ FAQ_SOP

I'm having the same problem here. It seems that you can't do ajax calls to https page while your current page is http. Just like you can't do calls to other domains. It's violation of SOP http://code.google.com/p/google-web-toolkit-doc-1-5/wiki/FAQ_SOP

这篇关于Ajax调用WCF窗口通过SSL服务(HTTPS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆