【问题标题】:HTTP 400 Bad Request error attempting to add web reference to WCF Service尝试将 Web 引用添加到 WCF 服务时出现 HTTP 400 错误请求错误
【发布时间】:2010-05-25 21:28:06
【问题描述】:

我一直在尝试将旧版 WSE 3 Web 服务移植到 WCF。由于保持与 WSE 3 客户端的向后兼容性是目标,因此我遵循了article 中的指导。

经过反复试验,我可以从我的 WSE 3 客户端调用 WCF 服务。但是,我无法从 Visual Studio 2005(安装了 WSE 3)添加或更新对此服务的 Web 引用。响应是“请求失败,HTTP 状态 400:错误请求”。尝试使用 wsewsdl3 实用程序生成代理时遇到相同的错误。我可以使用 VS 2008 添加服务参考。

我尝试在 Windows 7 和 Windows 2008 Server R2 上的 IIS 7.5 中托管该服务,结果相同。有任何解决方案或故障排除建议吗?

以下是我的 WCF 服务配置文件中的相关部分。

<system.serviceModel>
    <services>
      <service behaviorConfiguration="MyBehavior"
        name="MyService">
        <endpoint address="" binding="customBinding" bindingConfiguration="wseBinding"
          contract="IMyService" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      </service>
    </services>

    <bindings>
      <customBinding>
        <binding name="wseBinding">
          <security authenticationMode="UserNameOverTransport" />
          <mtomMessageEncoding messageVersion="Soap11WSAddressingAugust2004" /> 
          <httpsTransport/>
        </binding>
      </customBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior name="MyBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom"
              customUserNamePasswordValidatorType="MyCustomValidator" />
          </serviceCredentials>
          <serviceAuthorization principalPermissionMode="UseAspNetRoles" roleProviderName="MyRoleProvider" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  </system.serviceModel>

更新:在尝试了 Paul 的跟踪建议后,我确​​定异常是 System.Xml.XmlException: The body of the message can be read because it is empty

不幸的是,这似乎没有多大帮助。我注意到的另一件事是 serviceMetadata 元素有一个单独的 httpsGetEnabled 属性。我添加了它并将其设置为 true,因为这是一个 https 服务,但结果是一样的。似乎由于某种原因,WCF 没有识别出这是一个元数据请求。

【问题讨论】:

  • 当您在 IE 中键入 wsdl url 时,您看到了吗?如果您添加来自 VS 2010 的引用,它是否有效?

标签: .net wcf wse3.0


【解决方案1】:

您可以尝试在服务器上启用 WCF 跟踪。在&lt;/system.serviceModel&gt; 行之前插入

<diagnostics>

    <messageLogging 
     logEntireMessage="true" 
     logMalformedMessages="true" 
     logMessagesAtServiceLevel="true" 
     logMessagesAtTransportLevel="false" 
     maxMessagesToLog ="3000" />

</diagnostics>

&lt;/system.serviceModel&gt; 行之后插入此

<system.diagnostics>
    <sharedListeners>
        <add name="sharedListener" 
          type="System.Diagnostics.XmlWriterTraceListener"
          initializeData="c:\logs\tracelog.svclog" />
    </sharedListeners>
    <sources>
        <source name="System.ServiceModel" switchValue="Verbose, ActivityTracing" >
            <listeners>
                <add name="sharedListener" />
            </listeners>
        </source>
        <source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
            <listeners>
                <add name="sharedListener" />
            </listeners>
        </source>
        <source name="ApplicationLogging" switchValue="Information" >
            <listeners>
                <add name="sharedListener" />
            </listeners>
        </source>
    </sources>
</system.diagnostics>   

复制错误后,启动WCF tracing tool 并打开日志文件。可能发生了一些异常。

-- 编辑--

嗯,这是一个有趣的错误信息。它会带来更多的 Google 结果:

  1. Another stackoverflow question
  2. Could be fixed in next release of Windows 7
  3. TransferMode.StreamedResponse

【讨论】:

    【解决方案2】:

    我会做以下事情:

    <serviceMetadata httpGetEnabled="true" />
    

    改为:

    <serviceMetadata httpsGetEnabled="true" />
    

    还有。您是否设置了 HTTPS 绑定属性: http://blogs.msdn.com/b/wenlong/archive/2007/08/02/how-to-change-hostname-in-wsdl-of-an-iis-hosted-service.aspx

    【讨论】:

      猜你喜欢
      • 2011-12-07
      • 2011-08-25
      • 2018-02-01
      • 1970-01-01
      • 2013-11-27
      • 2022-01-13
      • 1970-01-01
      • 1970-01-01
      • 2012-04-27
      相关资源
      最近更新 更多