4

I'm receiving this error when I run a build outside Visual Studio:

"A property with the name 'httpRequest' is not present"

If I run the SAME code inside Visual Studio, it works. Does anyone have an idea of what I'm doing wrong?

My app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="CacheServiceEndpoint" />
        <binding name="consultaWebServicePortBinding" maxBufferPoolSize="524288" maxBufferSize="10485760"
  maxReceivedMessageSize="10485760">
          <readerQuotas maxDepth="32" maxStringContentLength="10485760"
            maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="Transport" />
        </binding>
        <binding name="consultaWebServicePortBinding1" />
      </basicHttpBinding>
      <customBinding>
        <binding name="CustomBinding_ICacheService">
          <binaryMessageEncoding />
          <httpTransport />
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="http://....svc"
          binding="basicHttpBinding" bindingConfiguration="CacheServiceEndpoint"
          contract="Cache.ICacheService" name="CacheServiceEndpoint" />
      <endpoint address="http://.../binary"
          binding="customBinding" bindingConfiguration="CustomBinding_ICacheService"
          contract="Cache.ICacheService" name="CustomBinding_ICacheService" />
      <endpoint address="https://..."
          binding="basicHttpBinding" bindingConfiguration="consultaWebServicePortBinding"
          contract="ABC.consultaWebService" name="consultaWebServicePort" />
    </client>
  </system.serviceModel>
</configuration>

What I am doing to make a call:

svc = new consultaWebServiceClient ("consultaWebServicePort");                    
svc.Endpoint.Behaviors.Add (new CustomEndpointBehavior (user, psw));

Thanks!

1
  • Please check that your .net framework is properly installed. I would suggest please try placing your system.web in your outside visual studio execution folder. Oct 6, 2014 at 4:27

1 Answer 1

11

I was having the exact same problem. I found the solution on the MSDN forum. I am posting it here as well because it was hard to find the solution, and I checked this Stack Overflow question first.

Apparently, when you run in the debugger, something it does initializes the HttpRequestMessageProperty, but when you run in a regular runtime environment, this Message property does not get initialized. I don't know what other Message properties might be missing, but probably others as well.

So you can write some code to create a new one and add it to the Message properties if it doesn't already exist. This seems to be safe to do. The header being added by my EndpointBehavior was indeed added and sent to the server.

private HttpRequestMessageProperty GetHttpRequestMessageProperty(Message request)
{
    if (!request.Properties.ContainsKey(HttpRequestMessageProperty.Name))
    {
        request.Properties.Add(HttpRequestMessageProperty.Name, new HttpRequestMessageProperty());
    }

    return request.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
}

Thanks to SteveSteveSteveP on the MSDN forums for the solution!

1
  • 1
    You saved me a decade of debugging. Aug 1, 2016 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.