WCF

WCF Examples

WCF

WCF Projects

WCF Project

Data Contract Generics
Previous Home Next

Generics are specific to .NET, and using them would avoid the service-oriented nature of WCF and use bounded generic types in your data contracts, as long as you specify the type parameters in the service contract and as long as the specified type parameters have valid data contracts.We cannot define WCF contracts that rely on generic type parameters.

Using bounded generic types Example

[DataContract]
class MyClass<T>
{
[DataMember]
public T m_MyMember;
}
[ServiceContract]
interface IMyContract
{
[OperationContract]
void MyMethod(MyClass<int> obj);
}

 

Collections

A collection is any type that supports the IEnumerable or IEnumerable<T> interfaces. All of the built-in collections in .NET, such as the array, the list, and the stack support these interfaces.

A data contract can include a collection as a data member, or a service contract can define operations that interact with a collection directly. Because .NET collections are .NET-specific, WCF cannot expose them in the service metadata, yet because they are so useful, WCF offers dedicated marshaling rules for collections.

Example:

ServiceContract]
interface IContactManager
{
   [OperationContract]
   IEnumerable<Contact> GetContacts( );
   ...
}
class ContactManager : IContactManager
{
   List<Contact> m_Contacts = new List<Contact>( );
   public IEnumerable<Contact> GetContacts( )
   {
      return m_Contacts;
   }
   ...
}
Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: