【问题标题】:WCF Service in IIS bindingsIIS 绑定中的 WCF 服务
【发布时间】:2015-10-15 02:33:43
【问题描述】:

我继承了一个托管在 IIS 下的 WCF 项目。它是常规网站的一部分,即也有可供人类使用的页面。

站点在 IIS 中配置有以下 2 个绑定:

1:https://www.example.com/ 2:http://www.example.com:8080/

如果我访问http://www.example.com:8080/my-service.svc?wsdl,我会得到一个按预期返回的 WSDL 文件。

如果我访问 https://www.example.com/my-service.svc?wsdl,我会被告知我需要访问 http://www.example.com:8080/my-service.svc?wsdl 来创建客户端。

web.config中system.serviceModel下没有绑定部分。

我想知道的是,服务如何知道它与第二个 IIS 绑定而不是第一个绑定相关联。

system.ServiceModel 如下:

<system.serviceModel>
    <extensions>
      <behaviorExtensions>
        <add name="FormsAuthBehavior" type="My-WCF.FormsAuthBehaviorExtensionElement, EcobuttonWebService" />
      </behaviorExtensions>
    </extensions>
    <behaviors>
      <serviceBehaviors>
        <behavior name="FormsAuthenticated">
          <!--To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment-->
          <serviceMetadata httpGetEnabled="true" />
          <!--To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information-->
          <serviceDebug includeExceptionDetailInFaults="false" />
          <!--Pre-authenticates client with server to generate FormsAuthentication cookie. Cookie is submitted with each WCF request.-->
          <!--NB: set throwsSecurityExceptions="false" when updating service references in client apps.-->
          <FormsAuthBehavior throwsSecurityExceptions="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
    <services>
      <service name="My-Service" behaviorConfiguration="FormsAuthenticated" />
    </services>
  </system.serviceModel>

【问题讨论】:

  • 显示您的 web.config 以便我们了解您做错了什么或错过了什么必要的事情?
  • 你能显示 web.config 吗?而且,在不公开 wsdl 的服务中,配置有以下行: ?
  • 好的,添加了system.ServiceModel部分。

标签: web-services wcf


【解决方案1】:

为 HTTP 传输安全配置 WCF 服务

<bindings>
      <basicHttpBinding>
        <binding name="secureHttpBinding">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

指定您的服务和服务端点,如以下 XML 所示。

<services>
      <service name="MySecureWCFService.Service1">
        <endpoint address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="secureHttpBinding"
                  contract="MySecureWCFService.IService1"/>

        <endpoint address="mex"
                  binding="mexHttpsBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>

启用 httpsGetEnabled

<serviceBehaviors>
<serviceMetadata httpsGetEnabled="true"/>
</serviceBehaviors>

参考资料:

MSDN

Seven simple steps to enable HTTPS on WCF WsHttp bindings

【讨论】:

  • 感谢您的评论,但这并不能回答我的问题,即当 web.config 中没有绑定时,服务当前如何知道其绑定是什么?
  • @DaleBurrell 获取 https://www.example.com/my-service.svc?wsdl 的 wsdl 您必须配置绑定、服务行为和端点 (mex)
  • 我就是这么想的!这就是我问这个问题的原因,因为它给了我一个没有任何绑定的 WSDL!除非它们可以以某种方式编译到 DLL 中?
  • 是否可以例如将此配置编译到 DLL 中?
  • @DaleBurrell 看看这个链接msdn.microsoft.com/en-us/library/ff647110.aspx
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-11-26
  • 2011-07-08
  • 2015-01-28
  • 2012-08-30
  • 1970-01-01
  • 1970-01-01
  • 2013-07-18
相关资源
最近更新 更多