【问题标题】:Cannot set wsHttpBinding on Azure Web Role. Web.config ignored?无法在 Azure Web 角色上设置 wsHttpBinding。 Web.config 被忽略?
【发布时间】:2013-04-24 21:08:56
【问题描述】:

我正在尝试使用wsHttpBinding 将 WCF 服务部署为 Windows Azure 角色。

当客户端尝试连接它时,它不断收到以下异常:

[SynchronizingContextState.Process] [System.Net.WebException: The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..]
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

这似乎表明该服务正在使用basicHttpBinding。但是,我多次检查了我的Web.config,似乎没有发现任何问题。此外,同样的服务在 Azure 之外托管时也能完美运行。

我连接到 Azure VM 并确认已部署正确的 Web.config,但它看起来好像只是被忽略了,因为我也无法获取服务元数据,即使它应该已启用。

这是我的Web.config 文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <customErrors mode="Off" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="BackendServiceBehavior">
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="BackendServiceBinding" maxReceivedMessageSize="655360">
          <security mode="None" />
        </binding>
      </wsHttpBinding>
    </bindings>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
      <service name="MyNamespace.BackendService" behaviorConfiguration="BackendServiceBehavior">
        <endpoint name="Backend" address="" binding="wsHttpBinding" bindingConfiguration="BackendServiceBinding" contract="MyNamespace.IBackendService" />
        <endpoint name="BackendMex" address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/BackendService.svc" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
</configuration>

我在这里遗漏了什么吗?非常感谢。

【问题讨论】:

    标签: wcf azure web-config wcf-binding


    【解决方案1】:

    您是否尝试添加到端点行为?

    <behavior name="web">
        <webHttp />
    </behavior>
    

    (如果您希望 MEX 也能正常工作)

    【讨论】:

    • 好吧,原来是命名空间问题,但我看错了地方。不过感谢您的回答!
    【解决方案2】:

    好的,我终于修好了,这是 PEBKAC 的一个坏案例。 =/

    我看到有人遇到同样的问题,因为他没有在服务名称中包含命名空间,所以我怀疑这是命名空间问题,但我一直在看错误的地方。

    原来服务的 Azure 实现是在错误的命名空间中定义的。我纠正了它,瞧,现在它可以工作了。

    希望这至少对其他人有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-12
      • 1970-01-01
      • 1970-01-01
      • 2015-04-12
      • 2019-03-17
      • 1970-01-01
      • 2016-09-13
      • 2014-12-21
      相关资源
      最近更新 更多