3

HTTPSトランスポート用にwcfwebapiサービスを構成するにはどうすればよいですか?これは彼らが変更すると言う領域の1つであるため、最終リリースでこれがどの程度変更されるかを誰かが知っていますか?

4

3 に答える 3

6

HTTPS をサポートするには、HttpBinding でトランスポート セキュリティを有効にする必要があります。これは、HttpConfigurableServiceHostFactory から派生させ、次のように CreateServiceHost をオーバーライドすることで実行できます。

public class HypertextTransferProtocolSecureServiceHostFactory : HttpConfigurableServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        var configurationBuilder = HttpHostConfiguration.Create();

        var host = new HttpConfigurableServiceHost(serviceType, configurationBuilder, baseAddresses);

        foreach (var endpoint in host.Description.Endpoints.Where(e => e.ListenUri.Scheme == "https"))
        {
            var binding = endpoint.Binding as HttpBinding;

            if (binding != null)
            {
                binding.Security.Mode = HttpBindingSecurityMode.Transport;
            }
        }
        return host;
    }
}

最後に、HypertextTransferProtocolSecureServiceHostFactory を RouteTable に追加する必要があります。

RouteTable.Routes.Add(new ServiceRoute("routePrefix", new HypertextTransferProtocolSecureServiceHostFactory(), typeof(ServiceType)));
于 2011-07-06T08:32:40.987 に答える
5

最新のドロップでは、HttpConfigurationオブジェクトを使用して、新しいホストを作成せずにバインディングを設定できます。これは、セキュリティモードを変更するために設定できるSetSecurityメソッドを公開します。

于 2011-09-02T15:48:15.310 に答える
2

これがGlobal.asaxからの構成です。URIを確認してから、正しいモードを使用します。IISおよびIISExpressで適切に機能します。。。。私の目標はHTTPS経由の基本ですが、IISExpressはHTTPURIを「バインディング」に保持し、それに対処しない限り、無限ループに陥ります(http://screencast.com/t/kHvM49dl6tP、http://screencast .com / t / 5usIEy5jgPdX

                var config = new HttpConfiguration
                       {
                           EnableTestClient = true,
                           IncludeExceptionDetail = true,
                           EnableHelpPage = true,
                           Security = (uri, binding) =>
                                          {
                                              if (uri.Scheme.Equals("https", StringComparison.InvariantCultureIgnoreCase)) 
                                                  binding.Mode = HttpBindingSecurityMode.Transport;
                                              else 
                                                  binding.Mode = HttpBindingSecurityMode.TransportCredentialOnly;

                                              binding.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
                                          },
                           CreateInstance = ((t, i, h) => container.Resolve(t))
                       };
于 2011-11-28T19:17:38.343 に答える