2010-12-21 43 views
1

我有一个在asp.net运行的网络服务,一切工作正常。现在我需要使用SSL访问该Web服务中的一些方法。当我使用http://与https://联系web服务时,它的工作原理非常完美:“我在https:// ...没有端点侦听”。如何在WCF Web服务中使用SSL?

您可以请帮我关于如何设置我的web.config以支持http和https访问我的Web服务。我试图遵循指导原则,但无法正常工作。

一些代码:

我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> 
+0

你有没有在IIS中设置的SSL网站正确,服务于同一个网站? – Rup 2010-12-21 15:48:57

+1

重新标记为包含wcf。我可能不是最好的人回答这个问题,但除了设置IIS之外,我相信在配置文件中还有设置让WCF知道使用哪个证书。 – 2010-12-21 16:07:14

+0

@Brian,但如果它是一个webhttpbinding,那么它是由IIS来协商证书 - 直到之后我才想到WCF才能涉足? – Rup 2010-12-21 17:10:15

回答

0

这听起来像有更多的与IIS的问题在端口443上没有听(用于HTTPS的端口)。检查IIS是否安装了证书并且它正在侦听安全端口。

1

而不是使用的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端点的作品为你