0

我正在调用一个服务,该服务现在托管在一个工作的 ASP.NET 站点中的 IIS 中。我的测试应用程序允许我创建服务引用并让我智能感知输入所有参数。调用该服务时,我收到以下错误:

内容类型 text/html;响应消息的 charset=UTF-8 与绑定的内容类型不匹配 (text/xml; charset=utf-8)。

我使用 fiddler(基于本网站上其他问题的信息)来查看返回的 html,并且我看到正在返回标准服务 Web 屏幕。以下是其中的一些文字:

要测试此服务,您需要创建一个客户端并使用它来调用该服务。您可以使用命令行中的 svcutil.exe 工具执行此操作,语法如下...

为什么我没有得到真正的服务响应?

这是 web.config 的那一部分:顺便说一句,我的网站是 https。

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://www.ed.net/Service.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
        contract="EdQuotingService.IService" name="BasicHttpBinding_IService" />
    </client>
  </system.serviceModel>

编辑:我们最终支付了微软支持请求来解决这个问题。他们是这样做的:我们请求 Global.asax 文件,我们发现其中有一个重定向代码,如下所示:

Protected Sub Application_BeginRequest(sender As Object, e As System.EventArgs)
    If HttpContext.Current.Request.IsSecureConnection.Equals(False) And mid(Request.ServerVariables("HTTP_HOST"), 1, 9) <> "localhost" Then
        Response.Redirect("https://" & Request.ServerVariables("HTTP_HOST") & HttpContext.Current.Request.RawUrl)
    End If

我们再次分析了我们拥有的所有数据,我们发现当我们尝试读取服务配置时,它无法读取配置文件,因此它使用了所有默认配置。这在跟踪中可以清楚地看到。这是因为它无法找到服务标签,因此它使用所有默认设置。我们还发现您的服务侦听 2 个端点——http 和 https。所以当我们浏览wsdl文件时我们发现你的服务基本上被配置为监听http而不是https。因此,我们发现您的方法 StartQuote 配置为侦听 http。因此,客户端为此接口调用 http 并且您的 global.asax 文件捕获了这个并重定向到 https。

从我们收集的 WCF 跟踪中,我们发现我们收到了未找到配置评估上下文的错误,然后是未找到匹配标记,如下所示:

未找到错误配置评估上下文意味着我们无法从配置文件中读取正确的配置。此外,由于 System.ServiceModel 标记下没有定义服务标记,因此它采用了默认配置,即没有 SSL 的 basichttpbinding。因此,当客户端尝试进行方法调用时,它将在 http 而不是 https 上进行调用,这会被您的 global.asax 文件拾取并将其重定向到 https。

我们继续在 System.ServiceModel 标签下添加了 Service 标签,如下所示:

<services>
  <service name="EdisonQuotingService">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="(binding name specified by you)_Transport"
      contract="IService" />
  </service>
</services>

<basicHttpBinding>
    <binding name="(binding name specified by you)">
      <security mode="Transport" />
    </binding>
  </basicHttpBinding>

我们进行了上述更改,之后当我们尝试从 WCF 服务调用 StartQuote 方法时,它运行良好,没有任何问题,并且您能够获得必要的数据。

4

0 回答 0