【问题标题】:Set WCF Service endpoints at server side web config for https在服务器端 Web 配置中为 https 设置 WCF 服务端点
【发布时间】:2022-01-16 16:18:22
【问题描述】:

我陷入了非常奇怪的境地,不知道如何解决这个问题。

我有一个非常简单的 WCF 服务,可以很好地使用 http,但现在我想将它移动到 https。

问题是需要托管的服务器。服务器 IIS 有一个带有 http 的别名“server-test.local”(不是“localhost”)。可以使用此别名在本地访问它。并将其映射到使用 https 的域名(例如,https://rmt.XXXXXXX.com)。

当我将 WCF 部署到该服务器并检查 WSDL 文件时,它具有本地别名而不是公共域名的映射。

它显示http://server-test.local/WCFService/Service.svc(错误)

我想要像https://rmt.XXXXXXXX.com/WCFService/Service.svc(正确)这样的映射

服务 web.config

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <pages controlRenderingCompatibilityVersion="4.0"/>
  </system.web>
  <system.serviceModel>

    <bindings>
      <basicHttpBinding>
        <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 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"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
   </system.serviceModel>
<system.webServer>    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

当我将服务引用添加到 app.它添加了以下不正确的端点。

客户端 App.config(端点)

<endpoint address="http://server-test.local/WCFService/Service.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProcessing"
        contract="WCFService.IService" name="BasicHttpBinding_IProcessing" />

我可以通过浏览器访问 url 和 WSDL 文件,但不能使用任何 Service 方法。我收到错误“没有可以接受消息的端点。”

我想我在这里遗漏了一些明显的东西。请建议我更改。

【问题讨论】:

    标签: c# .net wcf wcf-binding wcf-security


    【解决方案1】:

    您可以尝试更改web.config文件中的一些简单步骤,详情可以参考this post。
    1.在服务的web.config文件中开启传输层安全:

    <security mode="Transport">
      <transport clientCredentialType="None"/>
    </security>
    

    2.使用bindingConfiguration标签指定绑定名称,使用behaviorConfiguration标签配置行为,然后指定托管服务的地址。代码如下:

    <service name="***" behaviorConfiguration="***">
        <endpoint address= https://rmt.XXXXXXXX.com/WCFService/Service.svc 
          binding="basicHttpBinding"  
          bindingConfiguration="???" 
          contract="WCFService.IService"/>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
    </service>
    

    【讨论】:

      猜你喜欢
      • 2011-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-28
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      相关资源
      最近更新 更多