Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

.net

wcf

wse3.0

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.

like image 381
Kevin Krueger Avatar asked May 25 '10 21:05

Kevin Krueger


1 Answers

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
like image 111
Paul Williams Avatar answered Nov 09 '22 11:11

Paul Williams