2011-06-06 163 views
0

我正在嘗試爲我的Web服務中的更改決定架構。我需要做一個WCF服務。我只想製作一項服務,然後將其託管在IIS或Windows服務中。這甚至可能,使這種WCF服務的重用?我會如何去做這件事?這種情況是,我們的一些客戶無法啓動Windows服務,但可以在IIS中安裝WCF。在IIS和Windows服務中承載相同的WCF服務

預先感謝您。

回答

4

WCF服務僅僅是由WCF 託管接口遵守,然後提供一個客戶接口,允許它被訪問的組件。

在IIS,Windows服務,WinForm應用程序或控制檯應用程序中承載WCF服務發生同樣。這並不重要。

客戶端界面保持不變,但接口的公開方式可能會因託管方案而異。例如,您可能會在IIS情況下使用一個http綁定,但可能會對Windows服務使用TCP綁定。這些綁定可以在配置文件中定義,因此代碼不一定必須更改以適應以某種方式託管。

簡而言之,創建WCF服務應該獨立於最終如何託管。不過,爲了方便您的維護,我會選擇其中一種 - Windows服務或IIS。

0

你可以有一個Windows服務主機的WCF和暴露它的所有端點.. HTTP,TCP .. Windows服務比IIS好,因爲IIS本身是一個過程,然後我們放在它的VD主辦我們的網站/ WCF.As Windows服務,它將是一個專門的線程,迎合WCF.I我分享的Windows服務的app.config(細節更改),以顯示我們如何託管WCF ...希望它幫助..

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.diagnostics> 
    <sources> 
     <source name="System.ServiceModel" 
      switchValue="Off" propagateActivity="true" > 
     <listeners> 
      <add name="SERVICE_MONITOR" type="System.Diagnostics.XmlWriterTraceListener" 
       initializeData="MyApp_MONITOR.svclog" /> 
     </listeners> 
     </source>  
     <source name="MyApp_TRACE" switchValue="All" > 
     <listeners> 
      <add name="MyApp_TRACE_LISTENER" type="System.Diagnostics.XmlWriterTraceListener"           
       initializeData="MyApp_TRACE.svclog" /> 
     </listeners> 
     </source> 
    </sources> 
    <trace autoflush="true" /> 
    </system.diagnostics> 

    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="OverAllServiceBehavior"> 
      <serviceSecurityAudit 
      auditLogLocation="Application" 
      serviceAuthorizationAuditLevel="Failure" 
      messageAuthenticationAuditLevel="Failure" 
      suppressAuditFailure="true" />   
      <serviceDebug includeExceptionDetailInFaults="True" /> 
      <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" /> 
      <serviceThrottling maxConcurrentCalls="10000" maxConcurrentSessions="10000" 

      <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
      <serviceCredentials> 
      <userNameAuthentication 
       userNamePasswordValidationMode="Custom" 
       customUserNamePasswordValidatorType="MyAppHost.Authenticate, MyAppHost"/> 
      <serviceCertificate findValue="MyApp_MESSAGE" storeLocation="LocalMachine" 
           storeName="My" x509FindType="FindBySubjectName" />    
      <clientCertificate> 
       <authentication 
       certificateValidationMode="PeerTrust" 
       trustedStoreLocation="LocalMachine" /> 
      </clientCertificate> 
      </serviceCredentials>   
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="OverAllEndPointBehavior" /> 
     </endpointBehaviors> 
    </behaviors> 

    <bindings> 
     <basicHttpBinding> 
     <binding name="ServiceBasicHttpEndPointBinding" closeTimeout="00:00:59" 
       openTimeout="00:00:59" 

       messageEncoding="Text" 

      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 

         maxNameTableCharCount="2147483647" /> 
      <security mode="Message"> 
      <message clientCredentialType="Certificate"/> 
      </security> 
     </binding>  
     </basicHttpBinding> 
     <wsHttpBinding> 
     <binding name="ServiceWSHttpEndPointBinding" closeTimeout="00:00:59" 
       openTimeout="00:00:59" 


      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 

         maxNameTableCharCount="2147483647" /> 
      <security mode="TransportWithMessageCredential"> 
      <transport clientCredentialType="None" /> 
      <message clientCredentialType="Certificate"/> 
      </security>   
     </binding> 
     </wsHttpBinding> 
     <netTcpBinding> 
     <binding name="ServiceTCPEndPointBinding" maxBufferSize="2147483647" 

      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 

         maxNameTableCharCount="2147483647" /> 
      <security mode="TransportWithMessageCredential"> 
      <transport 
       clientCredentialType="Certificate" 
       protectionLevel="EncryptAndSign" /> 
      <message clientCredentialType="UserName" algorithmSuite="TripleDes"/> 
      </security> 
     </binding> 
     </netTcpBinding> 
    </bindings> 

    <services> 
     <service behaviorConfiguration="OverAllServiceBehavior" 
       name="MiddleWare.ServiceClasses.ServiceClass"> 

     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://127.0.0.1:15010/ServiceTCPEndPointMEX"/> 
      <add baseAddress="http://127.0.0.1:15020/ServiceHttpEndPointMEX"/> 
      <add baseAddress="https://127.0.0.1:15030/ServiceWSHttpEndPointMEX"/>    
      </baseAddresses> 
     </host> 

     <endpoint address="net.tcp://127.0.0.1:15040/ServiceTCPEndPoint" 


        contract="MiddleWare.ServiceContracts.IServiceContract" /> 

     <endpoint address="http://127.0.0.1:15050/ServiceBasicHttpEndPoint" 


        contract="MiddleWare.ServiceContracts.IServiceContract"/> 

     <endpoint address="https://127.0.0.1:15060/ServiceWSHttpEndPoint" 


        contract="MiddleWare.ServiceContracts.IServiceContract"/> 

     <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" /> 

     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 

     <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /> 

     </service> 
    </services> 
    </system.serviceModel> 
    <appSettings> 
    <add key="UserName" value="USER"/> 
    <add key="Password" value="PASSWORD"/> 
    </appSettings> 
</configuration> 
相關問題