WCF HTTPS在通过浏览器访问时工作,但不是后面的代码。 asp.net jquery

时间:2011-12-22 07:37:13

标签: wcf https

找不到我的问题的解决方案。我创建了一个wcf,我在我的asp.net页面上从jquery中消耗它。当我使用http://部署它时工作正常,但当我使用https://并将安全模式更改为传输时,我得到错误。但是如果我将安全模式设置为none,我可以从浏览器访问它。你能指导一下搞清楚吗?我正在将它部署到Windows Server 2003.谢谢!

 <system.serviceModel>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
    <behaviors>
      <endpointBehaviors>
        <behavior name="QPServiceAspNetAjaxBehavior">
          <enableWebScript />          
        </behavior>    
      </endpointBehaviors>      
    </behaviors>
    <services>      
      <service name="tService">
        <endpoint address="" behaviorConfiguration="tServiceAspNetAjaxBehavior"
          binding="webHttpBinding" bindingConfiguration="webBinding" contract="tService" />
      </service>   
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="webBinding">
          <security mode="None">
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>

2 个答案:

答案 0 :(得分:0)

要在Windows 7计算机上为https配置服务,请执行以下操作:

1.打开IIS。通过右键单击sites文件夹创建一个新网站,然后选择Add new website。

2.现在添加新网站弹出窗口。输入详细信息,然后在绑定部分选择类型为https,端口将更改为443,并显示SSL证书下拉列表。

3.从下拉菜单中选择用于保护本网站或本网站应用程序的沟通渠道的证书。

执行上述步骤后,您创建了一个侦听https的网站。现在只需在您的网站上托管您的应用程序,当您尝试在IE中浏览该服务时,您应该能够查看和访问它。

注意:我在您的配置中看到您尚未指定服务的命名空间。您需要拥有服务的完全限定名称和服务合同。

我有上面的设置,现在我有以下配置,我可以通过https浏览我的WCF服务:

<service name="Sample.SampleService" behaviorConfiguration="TransportSecurity">
        <endpoint address="" binding="webHttpBinding" bindingConfiguration="test" contract="Sample.ISampleService">          
        </endpoint>
      </service>

<webHttpBinding>
        <binding name="test">
          <security mode="Transport"></security>
        </binding>
      </webHttpBinding>

<behavior name="TransportSecurity">
          <serviceCredentials>
            <serviceCertificate findValue="localhost" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
          </serviceCredentials>
          <serviceMetadata httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>

答案 1 :(得分:0)

几次试错后。我找到了一个允许HTTP和HTTPS的wcf配置的解决方案,下面的配置是我的问题的解决方案。谢谢你回答我的问题。

  <system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
                           multipleSiteBindingsEnabled="true" />
<behaviors>
  <endpointBehaviors>
    <behavior name="QPServiceAspNetAjaxBehavior">
      <enableWebScript />
    </behavior>
  </endpointBehaviors>
</behaviors>
<services>
  <service name="QPService">        
    <!-- http and https        -->
    <endpoint address=""
              behaviorConfiguration="QPServiceAspNetAjaxBehavior" 
              binding="webHttpBinding"
              bindingConfiguration="webBindingSecure" 
              contract="QPService"/>        
    <endpoint address="" 
              behaviorConfiguration="QPServiceAspNetAjaxBehavior" 
              binding="webHttpBinding" 
              bindingConfiguration="webBinding" 
              contract="QPService" />

    <!--http
    <endpoint address="" behaviorConfiguration="QPServiceAspNetAjaxBehavior" binding="webHttpBinding" bindingConfiguration="webBinding" contract="QPService" />
    -->        
    <!--https        -->
    <endpoint address="" 
              behaviorConfiguration="QPServiceAspNetAjaxBehavior" 
              binding="webHttpBinding"
              bindingConfiguration="webBindingSecure" 
              contract="QPService"/>
  </service>
</services>
<bindings>
  <webHttpBinding>
    <binding name="webBinding">
      <security mode="None">
      </security>
    </binding>
    <binding name="webBindingSecure">
      <security mode="Transport">
      </security>
    </binding>
  </webHttpBinding>
</bindings>