0

有一个网络应用程序。它运行 2 个 wcf 服务,并且是另一个的客户端。一个 wcf 服务工作正常,另一个不能在开发服务器上工作,但在本地工作。错误是“响应消息的内容类型 text/html; charset=UTF-8 与绑定的内容类型不匹配”

Web 应用程序配置的 wcf 部分是

 <system.serviceModel>
<diagnostics>
  <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
  <service name="company.eShopWorld.Wcf.eShopWorldWCFService" behaviorConfiguration="company.Web.Wcf.ServiceBehavior">
   <endpoint address="" binding="basicHttpBinding" contract="Nad.CheckoutVendor.Interfaces.ICheckoutVendorService" /> 
   <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
  </service>
    <service name="company.Mobile.Wcf.MobileService" behaviorConfiguration="company.Mobile.Wcf.ServiceBehavior" />
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
    </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="company.Web.Wcf.ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>

      <behavior name="company.Mobile.Wcf.ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
  </serviceBehaviors>
</behaviors>
<bindings />
<client>
  <endpoint address="http://123.123.123.123:501/shipmentservice.svc" binding="basicHttpBinding" bindingConfiguration="" contract="Shipping.IShipmentWcfService" name="WSHttpBinding_IShipmentWcfService">
  </endpoint>
</client>

配置的测试客户端 wcf 部分是

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_ICheckoutVendorService" closeTimeout="00:02:00"
                openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02: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>
            <binding name="BasicHttpBinding_ICheckoutVendorService1" closeTimeout="00:02:00"
                openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02: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://test.com:50128/eShopWorldService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICheckoutVendorService1"
            contract="eShopWorldSvc.ICheckoutVendorService" name="BasicHttpBinding_ICheckoutVendorService" />
    </client>

移动服务有效,所以我认为 iis 设置正确。如果我将 svc url 放在浏览器中,它会显示服务页面,如果我将 wsdl 添加到 url,则会显示 wsdl。

2 天来我一直在反对这个问题,但找不到问题。

非常感谢任何帮助

所以尝试 Dimitri 的建议,我的 web.config 现在看起来像这样

 <services>
        <service name="company.eShopWorld.Wcf.eShopWorldWCFService" behaviorConfiguration="company.Web.Wcf.EshopServiceBehavior">
            <endpoint address="/eShopWorldService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICheckoutVendorService" contract="Nad.CheckoutVendor.Interfaces.ICheckoutVendorService"/>
            <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
        </service>
        <service name="company.Mobile.Wcf.MobileService" behaviorConfiguration="company.Mobile.Wcf.ServiceBehavior" >
            <endpoint address="/MobileService.svc" binding="basicHttpBinding" contract="company.Mobile.Wcf.IMobileService" />
            <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="company.Web.Wcf.EshopServiceBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>

            <behavior name="company.Mobile.Wcf.ServiceBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_ICheckoutVendorService" closeTimeout="00:02:00"
                openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02: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>

但我仍然有错误。请注意,我必须包含服务名称以防止出现 404 错误

每个服务都有自己的 web.config 以及 Web 应用程序的 web.config,这让我有些困惑。我假设它们在编译时会以某种方式卷入项目中,就好像它们中存在错误一样。还有其他想法吗?谢谢

4

3 回答 3

0

在您的 Web 应用程序(不是客户端)的配置中试试这个:

<system.serviceModel>
<diagnostics>
  <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
  <service name="company.eShopWorld.Wcf.eShopWorldWCFService" behaviorConfiguration="company.Web.Wcf.ServiceBehavior">
   <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICheckoutVendorService" contract="Nad.CheckoutVendor.Interfaces.ICheckoutVendorService" /> 
   <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
  </service>
    <service name="company.Mobile.Wcf.MobileService" behaviorConfiguration="company.Mobile.Wcf.ServiceBehavior" />
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
    </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="company.Web.Wcf.ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>

      <behavior name="company.Mobile.Wcf.ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
    <basicHttpBinding>
            <binding name="BasicHttpBinding_ICheckoutVendorService" closeTimeout="00:02:00"
                openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02: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://123.123.123.123:501/shipmentservice.svc" binding="basicHttpBinding" bindingConfiguration="" contract="Shipping.IShipmentWcfService" name="WSHttpBinding_IShipmentWcfService">
  </endpoint>
</client>
于 2012-11-06T20:32:05.127 回答
0

看起来您正在尝试使用相同的服务合同配置两个不同的服务。如果您真的想这样做,只需为同一服务中的不同端点定义不同的地址值,但这可能不是很有用。

如果移动服务公开了不同的合同,那么您确实需要两种不同的服务配置,每个合同一个。在这种情况下,克隆company.eShopWorld.Wcf.eShopWorldWCFServiceservice 元素并更改contract属性以使 Mobile 服务具有正确的 .NET 命名空间和接口类型。您还需要为每个服务提供单独的 *.svc 文件。我相信这两个服务的默认地址是这样的:

http://HostName/service.svc

http://HostName/mobileservice.svc
于 2012-11-06T20:32:11.593 回答
-1

所以问题原来是一个将服务名称转换为全小写的规则。它在 VS 调试中没有引起问题,但在 IIS 中出现了问题

于 2012-11-29T20:48:25.810 回答