HTTP 400 Bad Request error attempting to add web reference to WCF Service
Asked Answered
C

2

8

I have been trying to port a legacy WSE 3 web service to WCF. Since maintaining backwards compatibility with WSE 3 clients is the goal, I've followed the guidance in this article.

After much trial and error, I can call the WCF service from my WSE 3 client. However, I am unable to add or update a web reference to this service from Visual Studio 2005 (with WSE 3 installed). The response is "The request failed with HTTP status 400: Bad Request". I get the same error trying to generate the proxy using the wsewsdl3 utility. I can add a Service Reference using 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. Any solutions or troubleshooting suggestions?

Here are the relevant sections from the config file for my WCF service.

<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

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. I added that and set it to true since this is an https service, but the result was the same. It seems that for some reason WCF isn't recognizing that this is a metadata request.

Czardas answered 25/5, 2010 at 21:28 Comment(1)
when you type the wsdl url in IE do you see it? if you add a reference from VS 2010 does it work?Shutdown
W
3

You could try enabling WCF tracing on the server. Insert this before the </system.serviceModel> line:

<diagnostics>

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

</diagnostics>

Insert this after the </system.serviceModel> line:

<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. There is probably some exception occurring.

-- EDIT --

Well, that's an interesting error message. It leads to more Google results:

  1. Another stackoverflow question
  2. Could be fixed in next release of Windows 7
  3. TransferMode.StreamedResponse
Winger answered 25/5, 2010 at 21:42 Comment(0)
P
0

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

Pember answered 21/1, 2012 at 4:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.