在IIS和Windows服务中托管相同的WCF服务
我正试图为我的web服务的变化确定一个体系结构。我需要做一个WCF服务。我只想创建一个服务,然后将其托管在IIS或Windows服务中。这是否有可能实现WCF服务的这种重用?我该怎么做呢?我们的一些客户无权启动Windows服务,但可以在IIS中安装WCF在IIS和Windows服务中托管相同的WCF服务,windows,wcf,iis,windows-services,Windows,Wcf,Iis,Windows Services,我正试图为我的web服务的变化确定一个体系结构。我需要做一个WCF服务。我只想创建一个服务,然后将其托管在IIS或Windows服务中。这是否有可能实现WCF服务的这种重用?我该怎么做呢?我们的一些客户无权启动Windows服务,但可以在IIS中安装WCF 提前感谢。WCF服务只是遵循WCF宿主接口的程序集,然后提供允许访问它的客户端接口 托管WCF服务在IIS、Windows服务、WinForm应用程序或控制台应用程序中同样发生。这真的没关系 客户端接口保持不变,尽管接口的公开方式可能会因宿主
提前感谢。WCF服务只是遵循WCF宿主接口的程序集,然后提供允许访问它的客户端接口 托管WCF服务在IIS、Windows服务、WinForm应用程序或控制台应用程序中同样发生。这真的没关系 客户端接口保持不变,尽管接口的公开方式可能会因宿主场景的不同而有所不同。例如,您可能会在IIS案例中使用http绑定,但可能会在Windows服务中使用TCP绑定。这些绑定可以在配置文件中定义,因此代码不必更改以适应以这种或那种方式承载的情况
简言之,创建WCF服务应该独立于它最终的托管方式。不过,为了便于您的维护,我会选择其中一个—Windows服务或IIS。WCF服务只是一个遵循WCF宿主接口的程序集,然后提供一个允许访问它的客户端接口 托管WCF服务在IIS、Windows服务、WinForm应用程序或控制台应用程序中同样发生。这真的没关系 客户端接口保持不变,尽管接口的公开方式可能会因宿主场景的不同而有所不同。例如,您可能会在IIS案例中使用http绑定,但可能会在Windows服务中使用TCP绑定。这些绑定可以在配置文件中定义,因此代码不必更改以适应以这种或那种方式承载的情况
简言之,创建WCF服务应该独立于它最终的托管方式。不过,为了便于您的维护,我会选择其中一个—Windows服务或IIS。您可以让Windows服务承载WCF并公开其上的所有端点。..Http,TCP。。 Windows服务比IIS更好,因为IIS本身就是一个进程,然后我们会在其上放置一个VD来托管我们的网站/WCF。至于Windows服务,它将是一个专门的线程,仅适用于WCF。我正在共享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>
您可以让windows服务承载WCF并公开其上的所有端点..Http,TCP。。
Windows服务比IIS更好,因为IIS本身就是一个进程,然后我们会在其上放置一个VD来托管我们的网站/WCF。至于Windows服务,它将是一个专门的线程,仅适用于WCF。我正在共享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>