简体   繁体   English

如何在WCF Web服务中使用SSL?

[英]How to use SSL with a WCF web service?

I have a web service in asp.net running and everything works fine. 我在asp.net中运行了一个Web服务,并且一切正常。 Now I need to access some methods in that web-service using SSL. 现在,我需要使用SSL访问该Web服务中的某些方法。 It works perfect when I contact the web-service using http:// but with https:// I get "There was no endpoint listening at https://...". 当我使用http://与Web服务联系,但使用https://时,收到“没有端点在https:// ...监听”,它可以完美工作。

Can you please help me on how to set up my web.config to support both http and https access to my web service. 您能帮我设置我的web.config以支持对我的Web服务的http和https访问吗? I have tried to follow guidelines but I can't get it working. 我已尝试遵循指南,但无法正常工作。

Some code: 一些代码:

My TestService.svc: 我的TestService.svc:

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class TestService
{
    [OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    public bool validUser(string email) {
        return true;
    }
}

My Web.config: 我的Web.config:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
        <behaviors>
            <endpointBehaviors>
                <behavior name="ServiceAspNetAjaxBehavior">
                    <enableWebScript />
                </behavior>
            </endpointBehaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehavior">
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service behaviorConfiguration="ServiceBehavior" name="TestService">
                <endpoint address="" behaviorConfiguration="ServiceAspNetAjaxBehavior"
                     binding="webHttpBinding" bindingConfiguration="ServiceBinding"
                     contract="TestService" />
            </service>
        </services>
        <bindings>
            <webHttpBinding>
                <binding name="ServiceBinding" maxBufferPoolSize="1000000" maxReceivedMessageSize="1000000">
                    <readerQuotas maxDepth="1000000" maxStringContentLength="1000000" maxArrayLength="1000000" maxBytesPerRead="1000000" maxNameTableCharCount="1000000"/>
                </binding>
            </webHttpBinding>
        </bindings>
</system.serviceModel>

Instead of using the webHttpBinding , try creating a customBinding instead: 而不是使用webHttpBinding ,请尝试创建一个customBinding

<customBinding>
    <binding name="poxBindingHttps" closeTimeout="00:00:20">
        <textMessageEncoding writeEncoding="utf-8" />
        <httpsTransport manualAddressing="true"/>
    </binding>
    <binding name="poxBindingHttp" closeTimeout="00:00:20">
        <textMessageEncoding writeEncoding="utf-8" />
        <httpTransport manualAddressing="true"/>
    </binding>
</customBinding>

You'll also need to setup the webHttpBehavior like so: 您还需要像这样设置webHttpBehavior

<behaviors>
    <endpointBehaviors>
        <behavior name="ajaxBehavior">
            <enableWebScript/>
            <webHttp/>
        </behavior>
    </endpointBehaviors>
</behaviors>

And finally, your service & endpoint: 最后,您的服务和端点:

<services>
    <service name="TestService">
        <endpoint name="sslDefault" address="" binding="customBinding" bindingConfiguration="poxBindingHttps" behaviorConfiguration="ajaxBehavior" contract="TestService"/>
        <endpoint name="noSslDefault" address="" binding="customBinding" bindingConfiguration="poxBindingHttp" behaviorConfiguration="ajaxBehavior" contract="TestService"/>
    </service>
</services>

Hopefully that works out for you in creating an SSL endpoint 希望这对您创建SSL端点有帮助

It sounds like there is more an issue with IIS no listening on port 443 (The port used for HTTPS). 听起来IIS没有在端口443(用于HTTPS的端口)上进行监听的问题更多。 Check IIS that there is a certificate installed and that it is listening on the secure port. 检查IIS是否已安装证书,并且该证书正在安全端口上侦听。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM