473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Mapping between Schemata while serializing

Hi,
I'm looking for advice on mapping between different XML Schamata.
The C# (2.0) project I'm currently working on needs to send custom business
entities to multiple webservices, each accepting the same entity but in a
different schema.

As an extra complication the local entities are not serializable, so I have
implemented ISerializationSurrogate to fill the StreamingContext with object
data.

I'm looking for a way to map the name/value pairs in StreamingContext to the
target schema.

interface Local.IEntity { DateTime startDate; DateTime endDate;}
interface Remote.IEntity { DateTime[] days; }

What I have written so-far (see below) feels like I'm overcomplicating
things, please suggest a better way.

sealed class Local2RemoteSerializationBinder : SerializationBinder
{

public override Type BindToType(string assemblyName, string
typeName)
{
switch (typeName)
{
case "Local.Entity":
return typeof(Remote.Entity);
}
}
}

class Converter : ISerializationSurrogate {
Remote.IEntity Convert(Local.IEntity input)
{
SurrogateSelector ss = new SurrogateSelector();
ss.AddSurrogate(this);
StreamingContext sc = new
StreamingContext(StreamingContextStates.Remoting);
ISerializationSurrogate surrogate = new Converter();
IFormatter formatter = new BinaryFormatter(ss); // could be an
XML formatter
MemoryStream ms = new MemoryStream();

formatter.Serialize(ms, input);

// reset the memorystream
ms.Position = 0;
formatter.Binder = new Local2RemoteSerializationBinder();

return (Remote.IEntity)formatter.Deserialize(ms);
}

#region ISerializationSurrogate Members
//... removed for brevity
#endregion
}

--
Joris van Lier

Jun 27 '08 #1
0 1154

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark Johnson | last post by:
Is it possible that "information_schema.schemata" does not allways work correctly in MSDE Sql-Server. I have built an Explorer that will find the Servers (MSDE and SQL-Server 2000) and then...
0
by: Mark Johnson | last post by:
Is it possible that "information_schema.schemata" does not allways work correctly in MSDE Sql-Server. I have built an Explorer that will find the Servers (MSDE and SQL-Server 2000) and then...
0
by: Kenneth P | last post by:
Hi, I have installet MySql 4.1 db and am using .Net Connector successfully. I have a few databases with a lot of tables I'd like to migrate and aftewr I've converted them to access and am...
0
by: findus2007 | last post by:
Hi all, I have got an XML file, which I produced by serializing an object, which represents my data I want to be able to work with in Excel (Office 2003, Interop, no VSTO). When I do the mapping...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.