Service Hosting@H_403_2@@H_403_2@
服务托管@H_403_2@
l@H_403_2@Favor WAS Hosting when Server 2008 is an option
Ø@H_403_2@Multiple protocol support IIS Hosting model and tools
l@H_403_2@Favor IIS for external HTTP only services
Ø@H_403_2@process model
处理模型@H_403_2@
Ø@H_403_2@Better management tools
更好的管理工具@H_403_2@
l@H_403_2@Favor self-hosting for stateful services,callbacks,.NET Service Bus,debugging
l@H_403_2@Have a console-based debug self-host for development time
Ø@H_403_2@Can be a Windows Service project that is used for production self-hosting with a mode switch for debugging
l@H_403_2@Consider Dublin hosting in the future
Self Host Code@H_403_2@
自托管代码@H_403_2@
l@H_403_2@Do not put ServiceHost in a using statement in production code
Ø@H_403_2@Dispose can throw an exception that masks the real
Dispose
可以跑出掩盖事实的异常@H_403_2@
Ø@H_403_2@Exception thrown from Open call
Ø@H_403_2@Explicitly call Close in try/catch,log/ deal with exception in catch
Client Proxy Classes@H_403_2@
客户端代理类@H_403_2@
l@H_403_2@Favor static proxy class over ChannelFactory
Ø@H_403_2@Connection caching in the base class in 3.5
Ø@H_403_2@Place for encapsulation of common patterns
封装常用模式的地方@H_403_2@
l@H_403_2@Hand-code or micro-code generate proxy classes for internal services
Ø@H_403_2@Less bloated code
Ø@H_403_2@Share service contract and data contracts through libraries
通过类库共享服务和数据契约@H_403_2@
Ø@H_403_2@Explicit control over config file
l@H_403_2@Add Service Reference for external services or when you want an async API on the client
Ø@H_403_2@Clean up config after it destroys it
当你销毁它的时候,清楚配置@H_403_2@
Ø@H_403_2@Make sure to add references to data contract libraries before adding the service reference to avoid duplicate definitions
Ø@H_403_2@Live with the duplicate service contract definition instead of needing to repeatedly clean up the proxy code
Client Proxy Management@H_403_2@
客户端代理管理@H_403_2@
l@H_403_2@Cache client proxies if frequent calls to avoid session establishment cost
Ø@H_403_2@If secure / reliable session enabled
u@H_403_2@Check proxy state before using
使用之前检查代理的状态@H_403_2@
u@H_403_2@Get rid of proxy after exception
异常以后清除代理@H_403_2@
l@H_403_2@Don’t put proxies in a using statement
Ø@H_403_2@Dispose call might throw exception and mask real exception
Ø@H_403_2@Explicitly close in a try/catch block,and if Close throws an exception,abort the proxy to ensure resource clean up
Client Exception Management@H_403_2@
客户端异常管理@H_403_2@
l@H_403_2@All exceptions thrown from a service call derive from CommunicationException
l@H_403_2@FaultException could be wrapped unhandled exception on the client,or explicit error returned from the service
FaultException
可以被包装在一个客户端的未处理异常中,或者明确返回自服务@H_403_2@
l@H_403_2@FaultException<T> always an explicit error returned from the service
l@H_403_2@Simple approach:
Ø@H_403_2@Any exception from a proxy call,safe close the proxy
l@H_403_2@Advanced approach:
Ø@H_403_2@FaultException<T> - proxy is reusable
FaultException<T>-
代理是可以复用的@H_403_2@
Data Contracts@H_403_2@
数据契约@H_403_2@
l@H_403_2@Favor data contracts over serializable types
推荐使用可序列化类型作为数据契约@H_403_2@
Ø@H_403_2@More explicit model,better control over what the client sees
更清晰的模型,对于客户端说看到的数据进行更好的控制@H_403_2@
l@H_403_2@Implement IExtensibleDataObject
Ø@H_403_2@Avoids dropping data that the service / client does not understand
l@H_403_2@Avoid passing complex .NET specific types for interoperable services
Ø@H_403_2@DataSets and Exception types
l@H_403_2@Avoid XmlSerializer and MessageContracts except for interoperable scenarios and REST services
除了互操作的场景和@H_403_2@REST
服务,避免@H_403_2@XmlSerializer
(@H_403_2@XML
序列化器)和@H_403_2@MessageContracts
(消息契约)@H_403_2@
SOAP vs. REST@H_403_2@
SOAP@H_403_2@与@H_403_2@REST@H_403_2@
l@H_403_2@Favor SOAP services when you are writing a service that only your code will consume
当你编写的服务只有你自己使用时,推荐@H_403_2@SOAP
l@H_403_2@Favor REST services for publicly exposed,data oriented services
当你的服务是公开暴露、面向数据时,推荐使用@H_403_2@REST