首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >WCF:使用证书以编程方式配置服务

WCF:使用证书以编程方式配置服务
EN

Stack Overflow用户
提问于 2010-07-08 00:09:45
回答 2查看 4.7K关注 0票数 0

这是整个问题:我想创建WCF dll来访问WCF服务……唯一的问题是,当我使用WCF配置文件和一个有自己的app.config文件的应用程序时,WCF app.config文件被忽略......

我认为解决这个问题的一种方法是将我的app.config转换成代码,但不幸的是我不知道我在做什么。

如果您查看下面的app.config文件,您还可以看到我使用了一个带有编码值的证书,这使得我更难进行转换,因为正如我之前所说的,我不知道我在做什么,这对我来说是一种“边学边走”的方法。

有没有人知道如何实现原样使用app.config,而不是使用WCF服务访问应用程序的app.config?

有没有人有关于如何将下面的app.config翻译成C#的文章、工具或建议?

任何信息都是很棒的……谢谢,提前说好。

代码语言:javascript
运行
复制
<system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="customBindingHTTP">
          <security authenticationMode="SecureConversation">
            <localClientSettings maxClockSkew="23:30:00" />
            <secureConversationBootstrap authenticationMode="UserNameForSslNegotiated">
              <localClientSettings maxClockSkew="23:30:00" />
            </secureConversationBootstrap>
          </security>
          <binaryMessageEncoding maxReadPoolSize="20000000" maxWritePoolSize="20000000"
            maxSessionSize="20000000">
            <readerQuotas maxDepth="20000000" maxStringContentLength="20000000"
              maxArrayLength="20000000" maxBytesPerRead="20000000" maxNameTableCharCount="20000000" />
          </binaryMessageEncoding>
          <httpTransport maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000"
            maxBufferSize="20000000" useDefaultWebProxy="false" />
        </binding>
        <binding name="CustomBinding_ITestService">
          <security defaultAlgorithmSuite="Default" authenticationMode="SecureConversation"
            requireDerivedKeys="true" securityHeaderLayout="Strict" includeTimestamp="true"
            keyEntropyMode="CombinedEntropy" messageProtectionOrder="SignBeforeEncryptAndEncryptSignature"
            messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
            requireSecurityContextCancellation="true" requireSignatureConfirmation="false">
            <localClientSettings cacheCookies="true" detectReplays="true"
              replayCacheSize="900000" maxClockSkew="00:05:00" maxCookieCachingTime="Infinite"
              replayWindow="00:05:00" sessionKeyRenewalInterval="10:00:00"
              sessionKeyRolloverInterval="00:05:00" reconnectTransportOnFailure="true"
              timestampValidityDuration="00:05:00" cookieRenewalThresholdPercentage="60" />
            <localServiceSettings detectReplays="true" issuedCookieLifetime="10:00:00"
              maxStatefulNegotiations="128" replayCacheSize="900000" maxClockSkew="00:05:00"
              negotiationTimeout="00:01:00" replayWindow="00:05:00" inactivityTimeout="00:02:00"
              sessionKeyRenewalInterval="15:00:00" sessionKeyRolloverInterval="00:05:00"
              reconnectTransportOnFailure="true" maxPendingSessions="128"
              maxCachedCookies="1000" timestampValidityDuration="00:05:00" />
            <secureConversationBootstrap defaultAlgorithmSuite="Default"
              authenticationMode="UserNameForSslNegotiated" requireDerivedKeys="true"
              securityHeaderLayout="Strict" includeTimestamp="true" keyEntropyMode="CombinedEntropy"
              messageProtectionOrder="SignBeforeEncryptAndEncryptSignature"
              messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
              requireSecurityContextCancellation="true" requireSignatureConfirmation="false">
              <localClientSettings cacheCookies="true" detectReplays="true"
                replayCacheSize="900000" maxClockSkew="00:05:00" maxCookieCachingTime="Infinite"
                replayWindow="00:05:00" sessionKeyRenewalInterval="10:00:00"
                sessionKeyRolloverInterval="00:05:00" reconnectTransportOnFailure="true"
                timestampValidityDuration="00:05:00" cookieRenewalThresholdPercentage="60" />
              <localServiceSettings detectReplays="true" issuedCookieLifetime="10:00:00"
                maxStatefulNegotiations="128" replayCacheSize="900000" maxClockSkew="00:05:00"
                negotiationTimeout="00:01:00" replayWindow="00:05:00" inactivityTimeout="00:02:00"
                sessionKeyRenewalInterval="15:00:00" sessionKeyRolloverInterval="00:05:00"
                reconnectTransportOnFailure="true" maxPendingSessions="128"
                maxCachedCookies="1000" timestampValidityDuration="00:05:00" />
            </secureConversationBootstrap>
          </security>
          <binaryMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
            maxSessionSize="2048">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          </binaryMessageEncoding>
          <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
            maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
            bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
            realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
            useDefaultWebProxy="true" />
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="http://xx.xx.xxx.xxx:xxxx/TestService/custom"
        behaviorConfiguration="ClientCertificateBehavior" binding="customBinding"
        bindingConfiguration="customBindingHTTP" contract="ServiceReference1.ITestService"
        name="CustomBinding_ITestService">
        <identity>
          <certificate encodedValue="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx />
        </identity>
      </endpoint>
    </client>
    <behaviors>
      <endpointBehaviors>
        <behavior name="ClientCertificateBehavior">
          <clientCredentials>
            <serviceCertificate>
              <authentication certificateValidationMode="None" />
            </serviceCertificate>
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
EN

Stack Overflow用户

发布于 2010-07-08 00:43:34

下面的代码应该是您所需内容的一个很好的起点。我已经填写了我在app.config中看到的一些属性,并对它们进行了适当的设置。

代码语言:javascript
运行
复制
CustomBinding endpointBinding = new CustomBinding();

SymmetricSecurityBindingElement securityElement = SecurityBindingElement.CreateUserNameForSslBindingElement();
securityElement.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
securityElement.LocalClientSettings.MaxClockSkew = new TimeSpan(23, 30, 0);

endpointBinding.Elements.Add(securityElement);
endpointBinding.Elements.Add(new BinaryMessageEncodingBindingElement());
endpointBinding.Elements.Add(new HttpsTransportBindingElement());

至于证书..。一旦有了WCF服务主机对象,就可以像这样添加证书:

代码语言:javascript
运行
复制
 host.Credentials.ServiceCertificate.Certificate = cert;
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3196683

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档