0

I have an exception when I want to send a devExpress session in a composite type in WCF. I tried to make it serializable but I still get the error

information: Type System.Data.SqlClient.SqlConnection with data contract name SqlConnection:http://schemas.datacontract.org/2004/07/System.Data.SqlClient is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.

This the DataContract That I used.

[DataContract] 
[Serializable] 
[ServiceKnownType(typeof(Session))] 
[ServiceKnownType(typeof(SqlConnection))] 
[ServiceKnownType(typeof(SqlParameter))] 
public class CompositeType 
{
 Session sValue ; 
 [DataMember] 
 public Session SessionValue 
 { get {return sValue; } set {sValue = value; } } 

  }

I use also a method that send this class as parameter

void GetDataUsingDataContract(CompositeType composite); 
Akshay
  • 2,506
  • 4
  • 34
  • 55
Nouha
  • 33
  • 13
  • Could you provide more information about data or class that you send? – Selim Yildiz Mar 23 '20 at 10:40
  • `[DataContract] [Serializable] [ServiceKnownType(typeof(Session))] [ServiceKnownType(typeof(SqlConnection))] [ServiceKnownType(typeof(SqlParameter))] public class CompositeType { Session sValue ; [DataMember] public Session SessionValue { get {return sValue; } set {sValue = value; } } }` This the DataContract That I used. I use also a method that send this class as parameter ` void GetDataUsingDataContract(CompositeType composite); ` – Nouha Mar 23 '20 at 10:44
  • Add to your question as well please. And are you storing something with a database connection in session? – Selim Yildiz Mar 23 '20 at 10:46
  • My Goal is to create a session from devexpress xpo interface and then send it to wcf service to fill it with the information from the database – Nouha Mar 23 '20 at 10:56
  • XPO already has a built-in mechanism for transferring data via WCF services. Can you explain why this is not suitable for you? See: [Transferring Data via WCF Services](https://docs.devexpress.com/XPO/10018/feature-center/connecting-to-a-data-store/transferring-data-via-wcf-services) – Brendon Mar 23 '20 at 13:48

1 Answers1

2

XPO objects are tied to the data store via Session and you cannot send them over the wire.

If you want just to transfer raw data between computers, use a Data Transfer Object. XPO will retrieve data from the database on one side, and you will retrieve the data on the other side using WCF client methods.

XPO also supports a more complex scenario. If you want to use XPO on the client side but cannot create a direct database connection for security reasons, you can implement the IDataStore interface as a contract on the WCF side.

It is easy to implement the IDataStore interface, because all you need is to wrap an existing Data Store Adapter. All Data Store Adapters implement the IDataStore interface. XPO's Data Access Layer can use any IDataStore as a data source. This blog explains this approach: XPO is good for distributed applications.

Moreover, XPO has built-in WCF service and client components that already implement the IDataStore interface. All you need is to put them together. See examples here: Transferring Data via WCF Services.

Uranus
  • 1,690
  • 1
  • 12
  • 22
  • Thanks a lot for your answer. it's very helpful to understand the devexpress data transfer. I found some example that should be helpful [https://community.devexpress.com/blogs/xpo/archive/2011/05/17/xpo-11-1-sneak-peek-wcf-services-for-iobjectlayer.aspx] But my goal is that I should have a request-reply WCF. I think it isn't possible with devexpress and wcf with dataLayer transfer. I will implement another solution . thanks – Nouha Mar 24 '20 at 16:55
  • Uranus please can you look at this https://stackoverflow.com/questions/66647272/threadsafedatalayer-and-idatalayer-devexpress-xpo-cant-map-classinfo-to-same-ta –  Mar 21 '21 at 02:50