2011-07-20 163 views
1

我試圖實現的目標是,我的Windows服務將在有/無用戶登錄的計算機上定期運行,並將更新發送到遠程計算機(原始值)。在遠程機器上,WCF服務將回復一個格式化的值(如結果),並異步地用原始輸入更新數據庫。Windows服務代理客戶端訪問IIS 7託管的WCF服務器

Windows服務客戶端(WCF客戶端)=> IIS(WCF服務)=>數據庫(asynchonously) Windows服務客戶端(WCF客戶端)< = IIS(WCF服務)

我現在在做什麼,我主持在IIS中的WCF服務,但我的Windows服務(WCF客戶端)有問題的身份驗證和連接到WCF。我知道windows服務正在「LOCALSYSTEM」帳戶下運行。但在我打電話之前,我冒充了「網絡服務」。

  • 這種情況在WCF中可行嗎?

  • 我應該使用哪個帳戶?我可以在WCF客戶端硬編碼credentinals嗎?

  • 我嘗試了自簽名的證書,但我在IIS上側收到錯誤「鍵集未找到」在瀏覽器中打開WSDL

我當前綁定時: * NetTcpBinding的 *的wsHttpBinding

  • 如何設置每個支持我的目標的綁定?

WCF的web.config託管在IIS:

<system.serviceModel>  
<bindings> 
    <netTcpBinding> 
    <binding name="CustomNetTcpBinding" closeTimeout="00:02:30" openTimeout="00:02:30" 
     sendTimeout="00:02:30" listenBacklog="20" maxConnections="20"> 
     <readerQuotas maxDepth="512" maxStringContentLength="50000" maxArrayLength="50000" 
     maxBytesPerRead="50000" maxNameTableCharCount="512" /> 
     <security mode="Transport" /> 
    </binding> 
    </netTcpBinding> 
    <wsHttpBinding> 
    <binding name="CustomWsHttpBinding" closeTimeout="00:02:30" openTimeout="00:02:30" 
     sendTimeout="00:02:30"> 
     <readerQuotas maxDepth="512" maxStringContentLength="50000" maxArrayLength="50000" 
     maxBytesPerRead="50000" maxNameTableCharCount="512" /> 
    </binding> 
    </wsHttpBinding> 
</bindings> 
<diagnostics> 
    <messageLogging logMalformedMessages="false" logMessagesAtServiceLevel="false" 
    logMessagesAtTransportLevel="false" /> 
</diagnostics> 
<services> 
    <service behaviorConfiguration="TestAppWcfServiceApp.Service1Behavior" 
    name="TestAppWcfServerLib.TestAppServiceComposite2"> 
    <endpoint address="mexhttp" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    <endpoint address="nettcp" binding="netTcpBinding" bindingConfiguration="CustomNetTcpBinding" 
     contract="TestAppWcfServerLib.ITestAppServiceContract2" /> 
    <endpoint address="wshttp" binding="wsHttpBinding" bindingConfiguration="CustomWsHttpBinding" 
     contract="TestAppWcfServerLib.ITestAppServiceContract2" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="net.tcp://localhost:8005/TestApp" /> 
     <add baseAddress="http://localhost/TestApp" /> 
     </baseAddresses> 
     <timeouts openTimeout="00:02:30" /> 
    </host> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="TestAppWcfServiceApp.Service1Behavior"> 
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors>  

WCF客戶端在Windows服務:

<system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
      <binding name="NetTcpBinding_ITestAppServiceContract2" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" 
       hostNameComparisonMode="StrongWildcard" listenBacklog="10" 
       maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10" 
       maxReceivedMessageSize="65536"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
       <reliableSession ordered="true" inactivityTimeout="00:10:00" 
        enabled="false" /> 
       <security mode="Transport"> 
        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> 
        <message clientCredentialType="Windows" /> 
       </security> 
      </binding> 
     </netTcpBinding> 
     <wsHttpBinding> 
      <binding name="WSHttpBinding_ITestAppServiceContract2" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
       maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
       messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
       allowCookies="false"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
       <reliableSession ordered="true" inactivityTimeout="00:10:00" 
        enabled="false" /> 
       <security mode="Message"> 
        <transport clientCredentialType="Windows" proxyCredentialType="None" 
         realm="" /> 
        <message clientCredentialType="Windows" negotiateServiceCredential="true" 
         algorithmSuite="Default" /> 
       </security> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="net.tcp://ServerName/testtools/TestAppServApp.svc/nettcp" 
      binding="netTcpBinding" bindingConfiguration="NetTcpBinding_ITestAppServiceContract2" 
      contract="proxyClient.ITestAppServiceContract2" name="NetTcpBinding_ITestAppServiceContract2"> 
      <identity> 
       <servicePrincipalName value="host/ServerName" /> 
      </identity> 
     </endpoint> 
     <endpoint address="http://ServerName/testtools/TestAppServApp.svc/wshttp" 
      binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ITestAppServiceContract2" 
      contract="proxyClient.ITestAppServiceContract2" name="WSHttpBinding_ITestAppServiceContract2"> 
      <identity> 
       <servicePrincipalName value="host/ServerName" /> 
      </identity> 
     </endpoint> 
    </client> 
</system.serviceModel> 

我的設置:

  • 開發機: •Windows 7的64位企業版 •VS2010 SP1旗艦

  • 的Windows 2008 SP2的x86企業版 •IIS 7.0被激活

+0

你需要做什麼,這迫使你的Windows服務必須作爲LOCALSYSTEM運行 - 這是一個非常有特權的帳戶,你應該只使用,如果你沒有其他選擇。你也可以發佈服務配置,這樣我們就可以看到你是如何執行身份驗證的,等等。最後是機器是同一個域的一部分嗎? –

+0

您是否可以不使用普通帳戶,只需調整ACL即可訪問所需內容? –

+0

這不僅僅是它的功能。認爲它掃描了很多像WMI,RSOP,註冊表,文件和PInvoke對象 – altyne

回答

1

你不能可靠地使用與windows身份驗證兩臺機器在不同的域中。唯一可以實現這一目標的方法是在兩臺計算機上都使用相同的密碼對帳號進行同樣的調用。問題是他們沒有可以保證憑據正確的共享可信安全機構

您應該切換到使用證書或用戶名認證

+0

我試過(使用「-sky exchange -pe」參數的makecert自簽名證書路由),但我有問題在IIS中找到「找不到密鑰集」的問題。我已經通過MMC爲「網絡服務」帳戶添加了ACL,並使用FindPrivateKey.exe和winhttpcertcfg.exe驗證了鏈接。我正在努力如何使它工作。 – altyne

+0

只需讓IIS在IIS管理器 –

+0

的計算機節點上使用服務器證書工具生成自簽名證書,那麼我會嘗試使用該選項。我做了什麼,我在我的開發機器中創建了證書並導入到IIS中(一起使用私鑰) – altyne

相關問題