2011-06-06 160 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> 
相关问题