首页 > 解决方案 > 带有 IIS AAR 的 C# WCF 无法处理元数据

问题描述

我有一个使用 BasicHttpBinding 托管在 IIS 中的 WCF 服务。

WCF 可通过 IIS 获得,并通过 IIS 反向代理 (AAR) 路由到内部 HTTP 端口。

当我想从我的 IIS 将 WCF 嵌入 VisualStudio 时,我无法添加服务引用并收到此错误:

removeserver 已返回错误:(415)无法处理消息,因为内容类型为 'application/soap+xml; charset=utf-8' 不是预期的类型 'text/xml; charset=utf-8'..HTTP GET 错误 URI: http://myServer/WebServices/WCF_mywebapi/Service.svc

但是,如果我禁用 IIS ARR 反向代理(并直接在端口 80 上托管 WCF),则不会出现错误。ReverseProxy 处理我的请求是否有问题?我该如何调试它们?

我在 WsHttpBinding 上还有其他一些 Web 服务,它们在检索元数据方面效果很好。

web.config 必须是正确的,因为我可以在没有主动 ARR 的情况下嵌入服务。

我知道这个错误有一些解决方案,但没有一个提到 AAR 模块作为源。

你能帮助我吗?

编辑:这里来自 WCF 的 web.config:

   <?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.1">
      <assemblies>
        <add assembly="Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89B483F429C47342"/>
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5.1"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WcfNamespaces.Service.svc">
        <endpoint address="Service.svc" bindingNamespace="" binding="basicHttpBinding" bindingConfiguration="" contract="WcfNamespaces.IService"/>
         <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

我的代理服务器配置:

  <rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="http://127.0.0.1:1010/{R:1}" />
                </rule>

我为 IIS 代理实例禁用了 svc ISAPI 模块(因为由其他端口上的 IIS 实例处理):

    <handlers>
  <remove name="svc-ISAPI-4.0_64bit" />
  <remove name="svc-ISAPI-4.0_32bit" />
  <remove name="svc-Integrated-4.0" />
 </handlers>

谢谢 :)

标签: c#wcfiisarr

解决方案


推荐阅读