2010-01-11 51 views
2

我想在我的WCF服務(使用net.tcp綁定)託管在IIS 7中使用模擬。我已經到了它模擬客戶端,但每當我嘗試使用Settings.Default.SomeSetting訪問web.config中的任何配置設置時,都會引發SettingsPropertyNotFoundException。 這是因爲IIS在模擬身份下的身份不同?如果有,我必須更改哪些設置以允許它們在相同的模擬身份下運行? 我試過設置「servicePrincipalName」屬性沒有任何成功。訪問web.config設置使用WCF模擬與net.tcp綁定

以下附上我的web.config設置:

<system.serviceModel> 
    <services> 
     <service name="TestServices"> 
     <endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpbinding" 
      contract="Test.ITestService"> 
      <identity> 
      <servicePrincipalName value="NT AUTHORITY\NETWORK SERVICE" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mextcp" binding="mexTcpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services>   
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
    <bindings>   
     <netTcpBinding> 
     <binding name="tcpbinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" portSharingEnabled="true"> 
      <security mode="Transport"> 
      <transport clientCredentialType="Windows" protectionLevel="None"/> 
      <message clientCredentialType="Windows"/> 
      </security> 
     </binding> 
     </netTcpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true" /> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <serviceAuthorization impersonateCallerForAllOperations="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 

回答

2

看來我是不正確冒充我的客戶在服務器端,我需要我的客戶端上設置allowedImpersonationLevel以「模擬」 。這默認爲「標識」。所以當我使用WindowsIdentity.GetCurrent()進行測試時,我得到了正確的用戶名,但用戶並沒有真正模仿。

所以加入這個給我的客戶的web.config的伎倆:

<client> 
     <endpoint address="net.tcp://localhost/Test/Service/TestService.svc" 
      binding="netTcpBinding" bindingConfiguration="NetTcpBinding_ITestService" 
      contract="ServiceReference.ITestService" name="NetTcpBinding_ITestService" 
      behaviorConfiguration="ImpersonationBehavior"> 
     </endpoint> 
    </client> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="ImpersonationBehavior"> 
      <clientCredentials> 
      <windows allowedImpersonationLevel="Impersonation" /> 
      </clientCredentials> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors>