相关疑难解决方法(0)

来自控制台应用程序的HTTPS?

我没有使用IIS,甚至没有安装在这台计算机上.我的控制台托管的WCF REST服务中也没有任何app.config文件或web.config文件.但我想尝试在主机控制台应用程序上运行HTTPS:

class Program
{
    static void Main(string[] args)
    {
        string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
        ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
        //WebHttpBinding binding = new WebHttpBinding();
        //binding.Security.Mode = WebHttpSecurityMode.Transport;
        host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), "").Behaviors.Add(new WebHttpBehavior());
        host.Open();

        Console.WriteLine("Host opened");
        Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)

有没有办法让我的服务在HTTPS中运行?

c# rest https wcf web-services

31
推荐指数
1
解决办法
1万
查看次数

自托管WCF服务使用HTTP而不是HTTPS

好的,我在控制台应用程序中托管WCF服务.

所有绑定都以编程方式创建,因此没有配置设置.

我有一个工作服务,只要我使用HttpTransportBindingElement但是一旦我使用HttpsTransportBindingElement然后没有任何作用,该服务不会在浏览器中显示,客户端应用程序返回一个405 (Method Not Allowed) CommunicationException

我试过设置一个SecurityBindingElement我的CustomBinding但我不确定我应该使用哪个选项.

SecurityBindingElement.CreateCertificateOverTransportBindingElement()

SecurityBindingElement.CreateAnonymousForCertificateBindingElement()

等等

下面是创建主机的代码

baseAddress = new Uri(string.Format("{0}://{1}", strConnectionType, ConfigurationManager.AppSettings["baseAddress"]));

            ServiceHost host = new ServiceHost(typeof(IMyService), baseAddress);

            host.AddServiceEndpoint(typeof(MyService), binding, String.Empty);

            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpsGetEnabled = certificate != null;
            smb.HttpGetEnabled = certificate == null;

            host.Description.Behaviors.Add(smb);

            ServiceDebugBehavior sdb = host.Description.Behaviors.Find<ServiceDebugBehavior>();

            if (sdb == null)
            {
                host.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
            }
            else
            {
                if (!sdb.IncludeExceptionDetailInFaults)
                {
                    sdb.IncludeExceptionDetailInFaults = true;
                }
            }


            if …
Run Code Online (Sandbox Code Playgroud)

c# wcf

7
推荐指数
1
解决办法
2494
查看次数

自主WCF和SSL(再次)

我已经配置了ssl usign httpcfg set ssl,之后我编写了下一个代码:

using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Security;

namespace SelfHost
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            string addressHttps = String.Format("https://{0}:8000/hello", Dns.GetHostEntry("").HostName);

            var wsHttpBinding = new WSHttpBinding();
            wsHttpBinding.Security.Mode = SecurityMode.Transport;
            wsHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
            var serviceHost = new ServiceHost(typeof (HelloWorldService),new Uri(addressHttps));
            Type endpoint = typeof (IHelloWorldService);
            serviceHost.AddServiceEndpoint(endpoint, wsHttpBinding, "MyService");

            serviceHost.Credentials.ServiceCertificate.SetCertificate(
                StoreLocation.LocalMachine,
                StoreName.My,
                X509FindType.FindBySubjectName, "myhostname");
            serviceHost.Credentials.ClientCertificate.Authentication.CertificateValidationMode =
                X509CertificateValidationMode.PeerOrChainTrust;
            var smb = new ServiceMetadataBehavior();
            //            smb.HttpGetEnabled = true;
            smb.HttpsGetEnabled …
Run Code Online (Sandbox Code Playgroud)

.net c# ssl https wcf

6
推荐指数
1
解决办法
5419
查看次数

不使用IIS的WCF服务上的证书

我有一个WCF应用程序,通常在IIS中运行(对于我的测试和生产环境).但是当我从我的调试器运行它时,它被设置为运行自托管(即,弹出一个控制台窗口并且不使用IIS).

我还有一个连接到WCF应用程序的客户端应用程序.通常,当我测试我的客户端应用程序(在Windows Mobile上运行)时,它会设置为连接到我的一个测试环境(我有一个开发环境供我测试).

我现在遇到的问题是,客户端发送的内容与WCF应用程序的内容之间似乎存在脱节.我需要调试我的WCF应用程序.

我可以运行我的WCF应用程序,然后更改我的客户端的URL以指向调试器版本,但我的服务使用SSL运行并且具有客户端硬编码的证书.

我宁愿不禁用我的代码中的那部分(在客户端上).有没有办法在我的自托管WCF应用程序上安装证书?

ssl wcf certificate ssl-certificate

4
推荐指数
1
解决办法
6153
查看次数

标签 统计

wcf ×4

c# ×3

https ×2

ssl ×2

.net ×1

certificate ×1

rest ×1

ssl-certificate ×1

web-services ×1