共用方式為


Web Services and the Entity Data Model (Application Scenarios)

The Entity Data Model (EDM) provides a conceptual layer of abstraction over the data source. Object Services materializes entities defined in the conceptual layer into CLR objects that can be consumed in client applications, such as Windows Forms applications and ASP.NET applications. The Entity Framework supports serialization of entity objects into formats that enable remote and message-based exchange of entity objects, such as Web services and the Windows Communication Foundation (WCF). Objects can be serialized using binary serialization, XML serialization, and WCF contract serialization for transport using binary stream or message-based protocols. For more information, see Serializing Objects (Entity Framework). Objects can also be received from a message or stream, deserialized, and attached to an object context. For more information, see Attaching Objects (Entity Framework).

ADO.NET Data Services also enables you to provide dynamic access to EDM data in an XML format that can be used by applications. This entity data is accessed by using standard Representational State Transfer (REST) HTTP actions, such as GET, PUT, and POST. For more information, see ADO.NET Data Services Framework.

The following should be considered when creating Web services or WCF services that use the Entity Framework:

  • Full-graph serialization is supported for binary serialization and DataContract serialization. XML serialization does not serialize related objects.

  • Objects are always deserialized in the Detached state. You may need to attach or add the object to an ObjectContext, or you may just want to apply property changes to the original object. For more information, see Attaching Objects (Entity Framework).

  • Stateless services are recommended. Services should be designed such that an object context is only maintained for the duration of a request or a response. The message exchange pattern should include enough information so that changes can be applied without having to persist objects or re-query the data source to retrieve the original object. For example, a service that allows a client to update objects should require that the updated object be returned along with the original object. This enables changes to be applied to the original object by the Web service using the ApplyPropertyChanges method without having to retrieve the original object from the database or persist it in memory. For more information, see How to: Apply Changes Made to a Detached Object (Entity Framework).

See Also

Concepts

Object Services Overview (Entity Framework)