小编use*_*219的帖子

WCF或WSE编辑安全标头

我一直在尝试使用WCF或WSE更改soap安全元素.

  1. WCF:实现一个messageinspector并在Beforerequestsent中添加自定义代码.在后面的代码中设置了以下自定义绑定,我没有在ref System.ServiceModel.Channels.Message请求中看到一个安全元素.标题中有一个信封和Header,Body但缺少安全元素.

    AsymmetricSecurityBindingElement secBE = AsymmetricSecurityBindingElement.CreateMutualCertificateDuplexBindingElement(MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10);
    X509SecurityTokenParameters x509ProtectionParameters = new X509SecurityTokenParameters();
    x509ProtectionParameters.RequireDerivedKeys = false;
    x509ProtectionParameters.X509ReferenceStyle = X509KeyIdentifierClauseType.SubjectKeyIdentifier;
    x509ProtectionParameters.ReferenceStyle = SecurityTokenReferenceStyle.Internal;
    x509ProtectionParameters.InclusionMode = SecurityTokenInclusionMode.AlwaysToRecipient;
    
    Run Code Online (Sandbox Code Playgroud)

    这就是ref变量请求的样子

    <s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">  <s:Header>    <a:Action s:mustUnderstand="1" />    <a:MessageID>urn:uuid:4e929e4c-882b-40dc-9794-e54b71c47148</a:MessageID>    <a:ReplyTo>      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>    
    </a:ReplyTo>    
        <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo9rzFi9T6thDniQ9lRMdE0sAAAAA1RxuI+tGxUi69I44BS9+QcTNP3q82D9HmHmB8kuqWioACQAA</VsDebuggerCausalityData> 
     </s:Header> 
     <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">    <getEligibility xmlns="http://org/emedny/mhs/">      <input>        <transData</transData>      </input>  
      </getEligibility> 
      </s:Body>
    </s:Envelope>
    
    Run Code Online (Sandbox Code Playgroud)

    虽然fiddler显示了一个传出的安全头,但我无法访问Before request sent方法中的Security元素

  2. WSE:他们建议使用肥皂过滤器并覆盖一些方法,我在后面的代码中拥有所有令牌

        ProxyGenerationWSDL.MHService MHs = new MHService();
        X509Certificate2 cert = GetCertificateFromStore("User");
        X509SecurityToken x5091 = new X509SecurityToken(cert);
        MHs.SetClientCredential(x5091);
        X509Certificate2 cert2 = GetCertificateFromStore("Server");
        X509SecurityToken x5092 = new X509SecurityToken(cert2);
        MHs.SetServiceCredential(x5092);
        UsernameToken …
    Run Code Online (Sandbox Code Playgroud)

wcf wse

2
推荐指数
1
解决办法
2618
查看次数

递归查找Treeview节点

我有以下树

A
+-B
+-C 
| +-D
+-E
  +-F
  +-G
Run Code Online (Sandbox Code Playgroud)

我试图找到G给定的A

private TreeListNode FindTreeNode(TreeListNode node, Enumerations.ItemType type,
                                  Nullable<long> id)
{
    TreeListNode found = null;
    foreach (TreeListNode child in node.Nodes)
    {
        if ((Enumerations.ItemType)child[2] == type)
        {
            if (id == null)
            {
                found = child;
                break;
            }
            else
            {
                if ((long)child[0] == (long)id)
                {
                    found = child;
                    break;
                }
            }
        }
        else
        {
            if (child.HasChildren)
            {
                found = FindTreeNode(child, type, id);
                break;
            }
        }
    }
    return found;
}
Run Code Online (Sandbox Code Playgroud)
FindTreeNode(root,C,null)
Run Code Online (Sandbox Code Playgroud)

因为 …

c#

2
推荐指数
1
解决办法
4123
查看次数

布尔的逻辑

我的分析文件中有这个逻辑.用户可以选择输入文件.如果发生错误或者用户在输入文件中有无效条目,则逻辑检查并打印错误.

此方法返回bool成功.根据所有输入是否有效,取决于T/F. 如果success = T,则开始分析输入的下一步.现在这是我的问题.我如何归还假.

if (xxx > 100)
{
    errMsg = "Number of xxx should be <= 100";
    swRpt.WriteLine(errTitle + errMsg);
}
// sizing
;
swRpt.WriteLine("   Epsilon");

//Repair
success = Numerical.Check("repair", inputs.repair.ToString(), 
                          out dtester, out errMsg);
if (!success)
{
    swRpt.WriteLine(errTitle + errMsg);
}
success = Numerical.Check("prob", inputs.prob.ToString(), 
                          out dtester, out errMsg);
if (!success)
{
    swRpt.WriteLine(errTitle + errMsg);
}
Run Code Online (Sandbox Code Playgroud)

所以现在终于

if (success)
{
   //run the analysis method
}
if(!success)
{
   exit 
}
Run Code Online (Sandbox Code Playgroud)

即使一个输入错误,我也需要退出.第一个可能是错误的,最后一个可能是正确的输入值.

c#

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

C#表单X关闭和btnclose功能相同

如何为表单X(在最右上方)和关闭按钮创建相同的功能.这两个需要表现相似这就是我在btnClose_Click中所拥有的

     private void btnClose_Click(object sender, EventArgs e)
            {
                DialogResult result;
                int fileId = StaticClass.FileGlobal;
                if (DataDirty)
                {
                    string messageBoxText = "You have unsaved data. Do you want to save the changes and exit the form?";
                    MessageBoxButtons button = MessageBoxButtons.YesNo;
                    string caption = "Data Changed";
                    MessageBoxIcon icon = MessageBoxIcon.Question;
                    result = MessageBox.Show(messageBoxText, caption, button, icon);
                    if (result == DialogResult.No)
                    {
                        Program.fInput = new frmInputFiles(gtId, gName);
                        Program.fInput.Show();
                        this.Close();
                    }
                    if (result == DialogResult.Yes)
                    {
                        return;

                    }
                }
                else
                {
                    Program.fInput = new …
Run Code Online (Sandbox Code Playgroud)

c# winforms

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

Linq SelectMany.Distinct.ToList()

我正在寻找与此错误的一些输入。我对一些事情很清楚,但不确定如何解决此linq表达式。我们的用户会发生此错误,我无法重现此问题。因此,我试图找到在selectmany中使用不同运算符的位置,并在例程中发现了一个实例。

  var finishedReqs = allDocs.SelectMany(x => x.Reqs).Distinct().ToList();
  var finishedReqsWithDocs = finishedReqs.Where(x => x.Docs.Any());
  if (finishedReqsWithDocs.Any())
     {
     //Call another routine
     }
Exception
-----------------
Message:
Object reference not set to an instance of an object.

Stack Trace:
   at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
   at System.Linq.Enumerable.<DistinctIterator>d__81`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
Run Code Online (Sandbox Code Playgroud)

我了解如果集合为null,SelectMany将返回null而不是一个空列表。然后我很困惑,因为我们做了一个Distinct.ToList()。我需要在哪里检查空值。Resharper告诉我Distinct.ToList()的第一个表达式永远不能为null

if(finishedReqs!=null) //Resharper has squiggly lines with expression is always true
{
}
Run Code Online (Sandbox Code Playgroud)

c# linq

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

标签 统计

c# ×4

linq ×1

wcf ×1

winforms ×1

wse ×1