小编cro*_*arp的帖子

将IDictionary转换为Dictionary

我必须转换System.Collections.Generic.IDictionary<string, decimal>System.Collections.Generic.Dictionary<string, decimal>,而我不能.我尝试了ToDictionary方法,无法指定正确的参数.

我尝试过以下方法:

// my dictionary is PlannedSurfaces (of type IDictionary<string, decimal>)
blabla.ToDictionary<string, decimal>(localConstruction.PlannedSurfaces) 
Run Code Online (Sandbox Code Playgroud)

c# generics dictionary

28
推荐指数
2
解决办法
2万
查看次数

比较两个图像,并以%表示返回相似率

在我的项目中,我必须以任何格式(*.png,*.jpg,*.bmp等)比较两个图像,并返回百分比的相似率.

有没有人这样做?

如果有,怎么样?

.net c# image

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

消息中至少有一个安全令牌无法验证

服务器配置:

<?xml version="1.0"?>
<configuration>
<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceCredentialsBehavior">
                <serviceCredentials>
                    <serviceCertificate findValue="cn=cool" storeName="TrustedPeople" storeLocation="CurrentUser" />
                </serviceCredentials>
                <serviceMetadata httpGetEnabled="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="ServiceCredentialsBehavior" name="Service">
            <endpoint address="" binding="wsHttpBinding" bindingConfiguration="MessageAndUserName" name="SecuredByTransportEndpoint" contract="IService"/>
        </service>
    </services>
    <bindings>
        <wsHttpBinding>
            <binding name="MessageAndUserName">
                <security mode="Message">
                    <message clientCredentialType="UserName"/>
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client/>
</system.serviceModel>
<system.web>
    <compilation debug="true"/>
</system.web>
Run Code Online (Sandbox Code Playgroud)

我的客户端配置:

<?xml version="1.0" encoding="utf-8"?>
  <configuration>
<system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="LocalCertValidation">
                <clientCredentials>
                    <serviceCertificate>
                        <authentication certificateValidationMode="PeerTrust" trustedStoreLocation="CurrentUser" />
                    </serviceCertificate>
                </clientCredentials>
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IService" >
                <security mode="Message"> …
Run Code Online (Sandbox Code Playgroud)

security wcf web-services certificate wshttpbinding

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

SmtpClient超时不起作用

我已经设置了SmtpClient类的Timeout属性,但它似乎不起作用,当我给它一个1毫秒的值时,执行代码时超时实际上是15秒.我从msdn获取的代码.

string to = "jane@contoso.com";
string from = "ben@contoso.com";
string subject = "Using the new SMTP client.";
string body = @"Using this new feature, you can send an e-mail message from an application very easily.";
MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient("1.2.3.4");
Console.WriteLine("Changing time out from {0} to 100.", client.Timeout);
client.Timeout = 1;
// Credentials are necessary if the server requires the client 
// to authenticate before it will send e-mail on …
Run Code Online (Sandbox Code Playgroud)

c# timeout smtp

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

OpenXml电子表格.值过滤器,样式和unicode字符

由于文档很少,我在C#中遇到OpenXml SpreadSheetDocument问题.

  1. 如何使用过滤器制作顶行?
  2. 如何使颜色交替?
  3. 我想在我的SheetData中放入unicode字符,但是当我选择excel时它会给我一个错误..
  4. 更改顶行颜色.你能说是否有一些正确的方法可以做到这一点,比msdn上提供的更多文档,或者发布一些StyleSheet代码?对不起我的英语不好.谢谢.

.net c# openxml c#-4.0

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

找不到与绑定WSHttpBinding的端点的scheme http匹配的基址

我在我的本地计算机上进行了用户名/密码验证,使用自签名证书,一切正常,但是当我将我的应用程序放在IIS 7.5和Windows Server 2008 R2上时,它给了我错误:

无法找到一个基地址匹配具有绑定WSHttpBinding的端点的scheme http.注册的基地址方案是[https]. 我的网络服务cfg:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceCredentialsBehavior">
      <serviceCredentials>
        <serviceCertificate findValue="cn=AmicCert" storeName="Root" storeLocation="LocalMachine" />
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Util.CustomUserNameValidator, Util" />
      </serviceCredentials>
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="ServiceCredentialsBehavior" name="Service">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="MessageAndUserName" name="SecuredByTransportEndpoint" contract="IService" />
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="MessageAndUserName">
      <security mode="Message">
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
      <client />
   </system.serviceModel>
  <system.web>
<compilation debug="true" />
 </system.web>
 </configuration>
Run Code Online (Sandbox Code Playgroud)

.net c# xml https wcf

7
推荐指数
2
解决办法
3万
查看次数

WCF混合身份验证UserName和WIndows

可以使用两种类型的身份验证:wcf中的窗口和用户名,使用消息安全模式和证书进行身份验证.我的UserName身份验证cfg/code看起来:
Server cfg:

<?xml version="1.0"?>
  <configuration>
<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceCredentialsBehavior">
                <serviceCredentials>
                    <serviceCertificate findValue="cn=cool" storeName="TrustedPeople" storeLocation="CurrentUser" />
                    <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Util.CustomUserNameValidator, Util"  />
                </serviceCredentials>
                <serviceMetadata httpGetEnabled="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="ServiceCredentialsBehavior" name="Service">
            <endpoint address="" binding="wsHttpBinding" bindingConfiguration="MessageAndUserName" name="SecuredByTransportEndpoint" contract="IService"/>
        </service>
    </services>
    <bindings>
        <wsHttpBinding>
            <binding name="MessageAndUserName">
                <security mode="Message">
                    <message clientCredentialType="UserName"/>
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client/>
</system.serviceModel>
 <system.web>
    <compilation debug="true"/>
</system.web>
 </configuration>
Run Code Online (Sandbox Code Playgroud)

客户cfg:

<?xml version="1.0" encoding="utf-8"?>
  <configuration>
<system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="LocalCertValidation">
                <clientCredentials>
                    <serviceCertificate>
                        <authentication certificateValidationMode="PeerTrust" trustedStoreLocation="CurrentUser" />
                    </serviceCertificate>
                </clientCredentials>
            </behavior>
        </endpointBehaviors> …
Run Code Online (Sandbox Code Playgroud)

.net c# authentication wcf web-services

5
推荐指数
1
解决办法
4480
查看次数

Damerau-Levenshtein距离算法,禁用删除计数

如何在Damerau-Levenshtein距离算法的实现中禁用删除计数,或者如果已经实现了其他算法,请指向我.

示例(禁用删除计数):

string1:你好吗?

string2:oyu怎么样?

距离: 1(换位,4次删除不计算)

这是算法:

    public static int DamerauLevenshteinDistance(string string1, string string2, int threshold)
    {
        // Return trivial case - where they are equal
        if (string1.Equals(string2))
            return 0;

        // Return trivial case - where one is empty
        if (String.IsNullOrEmpty(string1) || String.IsNullOrEmpty(string2))
            return (string1 ?? "").Length + (string2 ?? "").Length;


        // Ensure string2 (inner cycle) is longer_transpositionRow
        if (string1.Length > string2.Length)
        {
            var tmp = string1;
            string1 = string2;
            string2 = tmp;
        }

        // Return …
Run Code Online (Sandbox Code Playgroud)

c# algorithm fuzzy levenshtein-distance

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

为什么wcf不允许没有http模块,通过传输安全模式进行用户名/密码验证

我想使用带有用户名/密码身份验证和ssl的传输安全模式,它适用于Windows身份验证:

<transport clientCredentialType="Windows"/>
Run Code Online (Sandbox Code Playgroud)

我在msdn上发现了一篇文章解释了如何使用传输安全模式进行用户名/密码身份验证,但需要自定义http模块.我感兴趣的是为什么没有默认安全模式,如:

<transport clientCredentialType="Username"/>
Run Code Online (Sandbox Code Playgroud)

如果我需要用户名/密码验证,我可以使用消息安全模式,但如果所有站点都使用https/ssl进行身份验证,那么在wcf中这样做应该不会有问题.
提前致谢.

.net c# security wcf wcf-security

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