繁体   English   中英

在 IIS 和 Windows 服务中托管相同的 WCF 服务

[英]Hosting the same WCF Service in IIS and in Windows Service

我正在尝试决定更改我的 web 服务的架构。 我需要做一个 WCF 服务。 我只想提供一项服务,然后将其托管在 IIS 或 Windows 服务中。 这是否可能,使这种 WCF 服务的重用? 我将如何 go 这样做? 场景是我们的一些客户无权启动 Windows 服务,但可以在 IIS 中安装 WCF。

先感谢您。

WCF 服务只是一个遵守 WCF托管接口的程序集,然后提供允许访问它的客户端接口。

托管 WCF 服务同样发生在 IIS、Windows 服务、WinForm 应用程序或控制台应用程序中。 真的没关系。

客户端接口保持不变,尽管接口的公开方式可能会根据托管方案而改变。 例如,您可能会在 IIS 案例中使用 http 绑定之一,但可能会使用 TCP 绑定为 ZAEAZ063489CE3AAB9404 服务。 这些绑定可以在配置文件中定义,因此不必更改代码以适应以一种或另一种方式托管。

简而言之,创建 WCF 服务应该独立于它最终将如何托管。 不过,为了便于您进行维护,我会选择其中一个 - Windows 服务或 IIS。

you could have a windows service host the WCF and expose all end points on it..Http,TCP.. Windows service is better than IIS because IIS is a process in itself and then we place upon it a VD to host our website/WCF .As for the Windows Service,it will be one dedicated thread catering only to the WCF.I am sharing the app.config of windows service (details changed) to show how we have hosted WCF...hope it helps..

<?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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM