本章说明:
实际开发中可能出现多种不同类型的服务,放在一起这是不合理的,我认为可以考虑在同一个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>