简体   繁体   English

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

[英]HTTP 400 Bad Request error attempting to add web reference to WCF Service

I have been trying to port a legacy WSE 3 web service to WCF. 我一直在尝试将传统的WSE 3 Web服务移植到WCF。 Since maintaining backwards compatibility with WSE 3 clients is the goal, I've followed the guidance in this article . 由于保持与WSE 3客户端的向后兼容性是我的目标,因此我遵循了本文中的指导。

After much trial and error, I can call the WCF service from my WSE 3 client. 经过多次试验和错误,我可以从我的WSE 3客户端调用WCF服务。 However, I am unable to add or update a web reference to this service from Visual Studio 2005 (with WSE 3 installed). 但是,我无法从Visual Studio 2005(安装了WSE 3)添加或更新此服务的Web引用。 The response is "The request failed with HTTP status 400: Bad Request". 响应为“请求失败,HTTP状态为400:错误请求”。 I get the same error trying to generate the proxy using the wsewsdl3 utility. 我尝试使用wsewsdl3实用程序生成代理时遇到同样的错误。 I can add a Service Reference using VS 2008. 我可以使用VS 2008添加服务引用。

I've tried hosting the service in IIS 7.5 on both Windows 7 and Windows 2008 Server R2 with the same result. 我尝试在Windows 7和Windows 2008 Server R2上的IIS 7.5中托管服务,结果相同。 Any solutions or troubleshooting suggestions? 任何解决方案或故障排除建

Here are the relevant sections from the config file for my WCF service. 以下是我的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>

UPDATE: After trying Paul's tracing suggestion, I have determined that the exception is System.Xml.XmlException: The body of the message cannot be read because it is empty 更新:在尝试了Paul的跟踪建议后,我确​​定异常是System.Xml.XmlException:无法读取消息正文,因为它是空的

Unfortunately, that doesn't seem to be of much help. 不幸的是,这似乎没有多大帮助。 One other thing I noticed was that there was a separate httpsGetEnabled attribute of the serviceMetadata element. 我注意到的另一件事是serviceMetadata元素有一个单独的httpsGetEnabled属性。 I added that and set it to true since this is an https service, but the result was the same. 我添加了它并将其设置为true,因为这是一个https服务,但结果是相同的。 It seems that for some reason WCF isn't recognizing that this is a metadata request. 似乎由于某种原因,WCF没有意识到这是元数据请求。

You could try enabling WCF tracing on the server. 您可以尝试在服务器上启用WCF跟踪。 Insert this before the </system.serviceModel> line: </system.serviceModel>之前插入:

<diagnostics>

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

</diagnostics>

Insert this after the </system.serviceModel> line: </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>   

After you duplicate the error, start the WCF tracing tool and open the log file. 复制错误后,启动WCF跟踪工具并打开日志文件。 There is probably some exception occurring. 可能发生了一些异常。

-- EDIT -- - 编辑 -

Well, that's an interesting error message. 嗯,这是一个有趣的错误信息。 It leads to more Google results: 它会带来更多Google搜索结果:

  1. Another stackoverflow question 另一个stackoverflow问题
  2. Could be fixed in next release of Windows 7 可以在Windows 7的下一个版本中修复
  3. TransferMode.StreamedResponse TransferMode.StreamedResponse

I would do the following: 我会做以下事情:

<serviceMetadata httpGetEnabled="true" />

change to: 改成:

<serviceMetadata httpsGetEnabled="true" />

Also. 也。 Have you set your HTTPS bindings up property: http://blogs.msdn.com/b/wenlong/archive/2007/08/02/how-to-change-hostname-in-wsdl-of-an-iis-hosted-service.aspx 您是否设置了HTTPS绑定属性: http//blogs.msdn.com/b/wenlong/archive/2007/08/02/how-to-change-hostname-in-wsdl-of-an-iis-hosted -service.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM