开发者

How to use SSL with a WCF web service?

I have a web service in asp.net running and everything works fine. Now I need to access some methods in that web-service using SSL. It works perfect when I contact the web-service using http:// but with https:// I get "There was no endpoint listening at 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. I have tried to follow guidelines but I can't get it working.

Some code:

My TestService.svc:

[ServiceCon开发者_运维技巧tract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class TestService
{
    [OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    public bool validUser(string email) {
        return true;
    }
}

My 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:

<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:

<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


It sounds like there is more an issue with IIS no listening on port 443 (The port used for HTTPS). Check IIS that there is a certificate installed and that it is listening on the secure port.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜