2010-07-07 87 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文件。