Sun_Blue_Sky

菩提本无树,明镜亦非台,本来无一物,何处惹尘埃 寻求内心的平静
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

WCF一个Web Application多个服务

Posted on 2013-02-28 15:38  Sun_Blue_Sky  阅读(424)  评论(0编辑  收藏  举报

本章说明:

实际开发中可能出现多种不同类型的服务,放在一起这是不合理的,我认为可以考虑在同一个Web Application中绑定多个Service。

 

Server Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBindingConfiguration" maxReceivedMessageSize="2147483647">
          <security mode="None">
          </security>
        </binding>
      </wsHttpBinding>
      <basicHttpBinding>
        <binding name="basicHttpBindingConfiguration" maxReceivedMessageSize="2147483647">
          <security mode="None">
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="behaviorConfiguration">
          <serviceDebug includeExceptionDetailInFaults="true"  />
          <serviceMetadata httpGetBinding="webHttpBinding" httpGetBindingConfiguration="" httpGetEnabled="true" />
          <serviceThrottling maxConcurrentSessions="10000"  maxConcurrentInstances="10000" maxConcurrentCalls="10000" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="behaviorConfiguration" name="WcfServer.RoleService">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpBindingConfiguration" contract="WcfServer.IRoleService" />
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />
      </service>
      <service behaviorConfiguration="behaviorConfiguration" name="WcfServer.UserService" >
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpBindingConfiguration" contract="WcfServer.IUserService" />
        <endpoint address="soap11" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingConfiguration"  contract="WcfServer.IUserService" />
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>
Client Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBindingConfiguration" >
          <security mode="None">
          </security>
        </binding>
      </wsHttpBinding>
      <basicHttpBinding>
        <binding name="basicHttpBindingConfiguration">
          <security mode="None">
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost/WcfServer/RoleService.svc"
     binding="wsHttpBinding" bindingConfiguration="wsHttpBindingConfiguration"
     contract="WcfServer.IRoleService" name="RoleService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <endpoint address="http://localhost/WcfServer/UserService.svc"
        binding="wsHttpBinding" bindingConfiguration="wsHttpBindingConfiguration"
        contract="WcfServer.IUserService" name="UserService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <endpoint address="http://localhost/WcfServer/UserService.svc/Soap11"
        binding="basicHttpBinding" bindingConfiguration="basicHttpBindingConfiguration"
        contract="WcfServer.IUserService" name="UserServiceSoap11">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>