首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过https浏览svc文件

通过https浏览svc文件
EN

Stack Overflow用户
提问于 2014-08-21 12:56:40
回答 2查看 512关注 0票数 0

我有个服务。我可以用http浏览它的svc文件。但是,我无法通过https访问它。我需要对它进行一些配置更改吗?下面是一个示例配置文件

代码语言:javascript
复制
  <?xml version="1.0"?>
  <configuration>

    <system.web>
      <compilation debug="true" targetFramework="4.0"/>
    </system.web>

    <system.serviceModel>

      <client>
      <endpoint address="http://localhost/Sum_Wcf/Service1.svc" binding="webHttpBinding"
      behaviorConfiguration="EndPointBehavior" contract="SumServiceReference.IService1" name="WebHttpBinding_Well" />
      </client>

      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>

        <standardEndpoints>
        <webScriptEndpoint>
          <standardEndpoint name="" crossDomainScriptAccessEnabled="true">
        </standardEndpoint>
        </webScriptEndpoint>
      </standardEndpoints>

      <behaviors>
        <endpointBehaviors>
          <behavior name="EndPointBehavior">
            <enableWebScript />
          </behavior>
        </endpointBehaviors>
      </behaviors>
   </system.serviceModel>

   <system.webServer>
      <modules runAllManagedModulesForAllRequests="true"/>
      <directoryBrowse enabled="true"/>
    </system.webServer>

  </configuration>

这是服务器端的配置文件。客户端元素在那里,因为它是一个演示应用程序,我在同一个应用程序中也有一个客户端应用程序,用于测试目的。

EN

回答 2

Stack Overflow用户

发布于 2014-08-21 17:36:58

WCF 4.0引入了默认端点、绑定和行为的概念。开箱即用,无需向配置文件添加任何内容,您将在.svc文件的位置获得一个默认端点,其默认绑定为basicHttpBindingbasicHttpBinding的默认安全模式是"None",所以即使其他配置都正确,我也不期望您能够通过SSL来浏览服务。

所以,首先是您的配置文件。您已经定义了客户端端点-如果您的服务正在调用另一个服务,那么您只需要在您的服务配置中使用这些端点,但它看起来并不是这样。您需要的是服务端点(默认情况下您有一个端点,但是您想要webHttpBinding,而不是basicHttpBinding

现在,如果您想坚持使用默认值(根据需要进行覆盖),您可以尝试如下所示:

代码语言:javascript
复制
<system.serviceModel>
  <bindings>
    <webHttpBinding>
      <binding>
        <security mode="Transport" />
      </binding>
    </webHttpBinding>
  </bindings>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true"
                             aspNetCompatibilityEnabled="true"/>
  <standardEndpoints>
    <webScriptEndpoint>
      <standardEndpoint name="" crossDomainScriptAccessEnabled="true" />
    </webScriptEndpoint>
  </standardEndpoints>
  <behaviors>
    <endpointBehaviors>
      <behavior>
        <enableWebScript />
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <protocolMapping>
    <add binding="webHttpBinding" scheme="https" />
  </protocolMapping>

这将为webHttpBindng设置一个默认配置(通过省略<binding>元素上的name属性),将securityMode设置为“传输”-这意味着使用该配置和webHttpBinding的任何服务都将使用您定义的绑定配置。

这同样适用于行为-默认情况下,指定的配置将用于端点,因为省略了name属性。

最后一部分是<protocolMappings>部分-在这里您将告诉应用程序使用webHttpBinding来传输https

您仍然可以像在WCF 3/3.5中那样显式定义端点。

我不确定(因为我没有使用SSL with WCF,或者webHttpBinding ),但是你可能也需要一个证书才能做到这一点,但是你可以尝试上面的方法,看看它是否能让你朝着正确的方向前进。

另外,请看一下我在对您的问题的评论中链接到的article,或者到谷歌搜索结果的链接以获取其他信息。

票数 1
EN

Stack Overflow用户

发布于 2014-08-21 14:30:53

您需要添加具有基本basichttpbinding标记和添加<security mode="Transport"/>的绑定xml标记

当然,您可以使用其名称https下面的名称来绑定所有配置:

代码语言:javascript
复制
  <basicHttpBinding>
    <binding name="https">
      <security mode="Transport" />
    </binding>
  </basicHttpBinding>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25418487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档