簡體   English   中英

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

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

我在asp.net中運行了一個Web服務,並且一切正常。 現在,我需要使用SSL訪問該Web服務中的某些方法。 當我使用http://與Web服務聯系,但使用https://時,收到“沒有端點在https:// ...監聽”,它可以完美工作。

您能幫我設置我的web.config以支持對我的Web服務的http和https訪問嗎? 我已嘗試遵循指南,但無法正常工作。

一些代碼:

我的TestService.svc:

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

我的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>

而不是使用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>

您還需要像這樣設置webHttpBehavior

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

最后,您的服務和端點:

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

希望這對您創建SSL端點有幫助

聽起來IIS沒有在端口443(用於HTTPS的端口)上進行監聽的問題更多。 檢查IIS是否已安裝證書,並且該證書正在安全端口上偵聽。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM