2010-07-07 8 views
0

Вот и вся проблема: я хочу создать DLL для WCF для доступа к службам WCF .... Единственная проблема, когда я использую конфигурационный файл WCF DLL с приложением, которое имеет СОБСТВЕННОЕ Файл app.config, файл WCF DLL app.config игнорируется .......WCF: программная настройка службы с сертификатом

Я считаю, что один из способов исправить эту проблему - перевести мой app.config на код, но, к сожалению, я не знаю что я делаю.

Если вы посмотрите файл app.config ниже, вы также увидите, что я использую сертификат с зашифрованным значением, что затрудняет мне перевод, потому что, как я уже говорил, я понятия не имею, что я я делаю это, это своего рода «научиться, когда идешь» для меня.

Кто-нибудь знает, как выполнить либо использование app.config как есть, но вместо службы WCF, доступ к app.config приложения APPLICATION?

ИЛИ

Кто-нибудь есть статьи, инструмент или советы о том, как перевести следующий 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

См. Руководство по безопасности WCF для CodePlex - http://wcfsecurity.codeplex.com - он содержит пошаговые решения практически для любого сценария, связанного с WCF/безопасностью –

ответ

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

Также вы можете поместить содержимое app.config файлов вашей библиотеки DLL в файл app.config приложения-вызывающего приложения.

Смежные вопросы