如何为支持 AJAX 的 WCF 服务同时启用 HTTP 和 HTTPS?

发布于 2024-12-27 17:20:31 字数 1013 浏览 0 评论 0原文

这是我的配置设置,目前仅允许 HTTP:

  <system.serviceModel>
<services>
  <service name="MyAjaxSvc">
    <endpoint address="" behaviorConfiguration="MyAjaxSvcEndpointBehavior"
              binding="webHttpBinding"
              contract="MyAjaxSvc" />
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="MyAjaxSvcEndpointBehavior">
      <enableWebScript />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

该服务可能会在我网站上的任何页面上调用。有些页面是 HTTPS,所以我想对其进行设置,以便可以使用任一协议调用(AJAX)服务。理想情况下,我希望所有 AJAX 服务调用都是 HTTPS,但由于不能混合协议,我将满足于允许使用当前页面使用的任何协议来调用服务。

Here is my config settings, which currently only allows HTTP:

  <system.serviceModel>
<services>
  <service name="MyAjaxSvc">
    <endpoint address="" behaviorConfiguration="MyAjaxSvcEndpointBehavior"
              binding="webHttpBinding"
              contract="MyAjaxSvc" />
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="MyAjaxSvcEndpointBehavior">
      <enableWebScript />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

This service could potentially be called on any page on my website. Some pages are HTTPS, so I would like to set it up so that the service can be called (AJAX) using either protocol. Ideally, I would like all my AJAX service calls to be HTTPS, but since you can't mix protocols, I will settle for allowing the service to be called using what ever protocol the current page is using.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偷得浮生 2025-01-03 17:20:31

在黑暗中拍摄:

您需要添加另一个绑定(通常在您显示的代码上方声明),然后声明另一个端点。

Shot in the dark:

You'll need to add another Binding (declared above the code you show (normally)), and then declare another endpoint.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文