2010-07-07 127 views
0

这里的整个问题:我想创建WCF DLL访问WCF服务....唯一的问题是,当我使用WCF DLL配置文件与具有应用它自己的app.config文件中,WCF DLL app.config文件被忽略.......WCF:编程与证书配置服务

我想一个办法来解决这个问题是把我的app.config代码,但不幸的是我不知道我在做什么。

如果你看下面的app.config文件,你也可以看到我使用了一个带有编码值的证书,这使得我翻译起来更加困难,因为就像我之前说过的,我不知道我在做什么我在做什么,这对我来说就是“为你学习”。

有谁有如何做到既能够原样使用的app.config,而不是WCF服务访问应用程序的app.config任何想法?

OR

有没有人对如何翻译下面的app.config到C#的文章,工具或建议吗?

任何信息将是非常美妙.....谢谢提前。

<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> 
+0

见CodePlex上,基于WCF安全指南 - http://wcfsecurity.codeplex.com - 它拥有几乎任何WCF- /安全相关的场景中一步一步的解决方案 – 2010-07-07 16:15:10

回答

0

下面的代码应该是您需要的良好起点。我已经填充了,我在你的app.config看到并正确设置它们的属性了一把。

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服务宿主对象,你可以添加证书,像这样:

host.Credentials.ServiceCertificate.Certificate = cert; 
0

你也可以把你的DLL的app.config文件内容到调用者应用程序的app.config文件。