属性"httpRequest"不存在 [英] Property httpRequest' not present

查看:63
本文介绍了属性"httpRequest"不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio外部运行构建时收到此错误:

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

不存在名称为'httpRequest'的属性"

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

如果我在Visual Studio中运行SAME代码,它将起作用.有人知道我在做什么错吗?

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

我的app.config:

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>

我正在打电话的内容:

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

谢谢!

推荐答案

我遇到了完全相同的问题.我在

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.

显然,当您在调试器中运行时,它确实会初始化HttpRequestMessageProperty,但是在常规运行时环境中运行时,不会初始化此Message属性.我不知道可能还会缺少其他哪些Message属性,但是可能还有其他属性.

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.

因此,您可以编写一些代码来创建新代码,如果尚不存在,则将其添加到Message属性中.这似乎是安全的.我的EndpointBehavior添加的标头确实已添加并发送到服务器.

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;
}

在MSDN论坛上感谢 SteveSteveSteveP .解决方案!

Thanks to SteveSteveSteveP on the MSDN forums for the solution!

这篇关于属性"httpRequest"不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆