小编fli*_*erg的帖子

MongoDB,条件upsert或更新

当使用MongoDB时,我正在进行条件upsert作为聚合过程的一部分,在表单上(简化了很多):

db.dbname.update({attr1 : value1, attr2 : value2},
                 {"$inc" : { avg : current_value, nr : 1}},
                 false (multi), true (upsert))
Run Code Online (Sandbox Code Playgroud)

但我希望能够保持最大(和最小)值,而无需检索文档.有点像:

db.dbname.update({ attr1 : value1, attr2 : value2},
                 {"$inc" : { avg : current_value, nr : 1},
                  "$setIfBigger" : { max : current_value}},
                 false (multi), true (upsert))
Run Code Online (Sandbox Code Playgroud)

这有可能以有效的方式实现吗?

我当前的,效率极低的解决方案是我检查当前的聚合文档,如果它存在,我相应地更新值,如果不存在,我创建一个新文档.示例(再次,简化了很多,但实质是那里):

var obj = db.dbname.findOne({attr1 : value1, attr2 : value2},{_id:1});
if (obj != null) {
   db.dbname.update({attr1 : value1, attr2 : value2},
                    {"$inc" : { avg : current_value, nr : 1},
                     "$set" : …
Run Code Online (Sandbox Code Playgroud)

javascript database mongodb

13
推荐指数
1
解决办法
1万
查看次数

C#.NET 4.0 WCF MessageSecurityException,"安全标头为空." 在消费服务时

在项目中使用WCF和C#时,我得到一个异常MesssageSecurityException,消息"Security header为空".以下是响应(根据MS Service Trace Viewer):

    <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://www.w3.org/2005/08/addressing">
      <soapenv:Header>
        <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="true"></wsse:Security>
        <wsa:Action>_WHAT_I_DID_</wsa:Action>
        <wsa:RelatesTo>_MSG_ID_OF_REQUEST_</wsa:RelatesTo>
      </soapenv:Header>
      <soapenv:Body>
        _CORRECT_BODY_
      </soapenv:Body>
    </soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)

实际上,安全标头是"空的",但据我所知,它仍然正确地适应安全标头定义.

我也尝试过编辑绑定,但这似乎也没有帮助.我也发现了一个类似的问题,启用EnableUnsecuredResponse会有所帮助,但它不在这里.

以下是SoapUI的回复:

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://www.w3.org/2005/08/addressing">
   <soapenv:Header>
      <wsse:Security soapenv:mustUnderstand="true" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"/>
      <wsa:Action>_WHAT_I_DID_</wsa:Action>
      <wsa:RelatesTo>_REQ_MSG_ID_</wsa:RelatesTo>
   </soapenv:Header>
   <soapenv:Body>
      _CORRECT_BODY_
   </soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)

除了关闭安全标头之外,它们几乎完全相同.哪个有趣,但不应该提出例外?

我还发现了一个类似的问题,其中解决方案是创建一个自定义消息编码器并剥离整个安全标头,尽管这将是一个额外不需要的步骤.这是用.Net和WCF做的唯一方法吗?没有内容,WCF不能处理安全头吗?

编辑:澄清问题,是编写一个编码器,它丢弃安全头是使用WCF接收和解析带有空安全头的SOAP消息的唯一方法吗?

EDIT2:添加conf的一部分:

    <binding name="NinjaBinding">
      <security allowSerializedSigningTokenOnReply="true" enableUnsecuredResponse="true"
      authenticationMode="UserNameOverTransport" requireDerivedKeys="false"
      securityHeaderLayout="Lax" includeTimestamp="false" allowInsecureTransport="true"
      keyEntropyMode="ClientEntropy"
      messageProtectionOrder="SignBeforeEncryptAndEncryptSignature"
    messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
      requireSecurityContextCancellation="false">
        <localServiceSettings detectReplays="false" />
        <secureConversationBootstrap _IDENTICAL_TO_ABOVE_
        </secureConversationBootstrap>
      </security>
      <textMessageEncoding />
      <httpsTransport />
    </binding>
Run Code Online (Sandbox Code Playgroud)

据我所知,它的配置允许几乎所有东西?

.net c# wcf soap visual-studio-2010

7
推荐指数
1
解决办法
4467
查看次数

我的简单MSIL出了什么问题?

我正在尝试生成以下类:

public class MyType
{
    public string MyMethod() { return "Hi"; }
}
Run Code Online (Sandbox Code Playgroud)

我的Emit代码如下:

var assemblyBuilder = GetAssemblyBuilder("MyAssembly");
var moduleBuilder = assemblyBuilder.DefineDynamicModule("MyModule");
var typeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public);
var methodBuilder = typeBuilder.DefineMethod("MyMethod", MethodAttributes.Public, typeof(string), new Type[] { });
var ilBuilder = methodBuilder.GetILGenerator();
ilBuilder.Emit(OpCodes.Nop);
ilBuilder.Emit(OpCodes.Ldstr, "Hi");
ilBuilder.Emit(OpCodes.Stloc_0);
ilBuilder.Emit(OpCodes.Br_S);
ilBuilder.Emit(OpCodes.Ldloc_0);
ilBuilder.Emit(OpCodes.Ret);
var type = typeBuilder.CreateType();
Run Code Online (Sandbox Code Playgroud)

但是当我调用MyMethod一个实例时,MyType我得到一个InvalidProgramException:Common Language Runtime检测到一个无效的程序.

我已经尝试将返回类型更改为void并使用just EmitWriteLineEmit(OpCodes.Ret),运行正常,所以它必须是我在这里写的IL.

我错过了一些明显的东西吗?一个明确的解释将有所帮助,因为我刚刚开始使用Emit.

评论中的其他信息:

"原始"IL取自LINQ-pad中的IL-generation.

c# cil reflection.emit

4
推荐指数
1
解决办法
228
查看次数

属性属性应该是虚拟的吗?

MSDN 上,编写自定义属性的示例显示了以下奇怪的行为

[AttributeUsage(AttributeTargets.All)]
public class MyAttribute : Attribute
{ 
  public virtual string Name
  {
    get {return name;}
  }

  // Define Level property. 
  // This is a read-only attribute. 

  public virtual string Level
  {
    get {return level;}
  }

  // Define Reviewed property. 
  // This is a read/write attribute. 

  public virtual bool Reviewed
  {
    get {return reviewed;}
    set {reviewed = value;}
  }
}
Run Code Online (Sandbox Code Playgroud)

为什么所有的财产都是虚拟的?

c# virtual attributes

0
推荐指数
1
解决办法
1187
查看次数

具有嵌套结构作为属性的类不起作用

为什么以下代码不起作用?如果我h从一个属性更改为一个字段,它就可以了!或者,如果我改变FileHeader来自structclass它的作品!我只是在找一个为什么它不起作用的答案.

public class MyFile
{
    public struct FileHeader
    {
        public List<string> ColNames
        {
            get;
            set;
        }

        public void setColNames()
        {
            ColNames = new List<string>();
            ColNames.Add("address");
        }
    }

    public FileHeader h
    {
        get;
        set;
    }
}

public class Program
{
    static void Main(string[] args)
    {
        MyFile o = new MyFile();
        o.h.setColNames();

        Console.WriteLine(o.h.ColNames[0]); // <- Doesn't work! No elements

        string line = System.Console.ReadLine();
    }
}
Run Code Online (Sandbox Code Playgroud)

c# struct properties

0
推荐指数
1
解决办法
169
查看次数