尝试将Web引用添加到WCF服务时出现HTTP 400 Bad Request错误

Kev*_*ger 7 .net wcf wse3.0

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

经过多次试验和错误,我可以从我的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>
Run Code Online (Sandbox Code Playgroud)

更新:在尝试了Paul的跟踪建议后,我确​​定异常是System.Xml.XmlException:无法读取消息正文,因为它是空的

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

Pau*_*ams 3

您可以尝试在服务器上启用 WCF 跟踪。在该行之前插入</system.serviceModel>

<diagnostics>

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

</diagnostics>
Run Code Online (Sandbox Code Playgroud)

在该行后面插入以下内容</system.serviceModel>

<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>   
Run Code Online (Sandbox Code Playgroud)

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

- 编辑 -

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

  1. 另一个 stackoverflow 问题
  2. 可能会在 Windows 7 的下一版本中修复
  3. TransferMode.StreamedResponse