473,625 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlSerializatio n - Implementing dynamic "caster"?? (cast Type not know until run-time)

I am trying to create a generic SOA ServiceInvoker that will accept an
XML string that will be used to deserialize an object generated by
XSDObjectGen. The hierarchy goes like this:
Requests...Requ est (1..n)... Payload (1)... PayloadCollecti on (1) ...
Payload (0...n)

I have the knowledge about the root object Responses which I can create
directly. However I don't know what is the type for Request and Payload
(These will be versioned classes and its class names will be stored in
a Requests repository (a .config file)

(See code to follow)
In my ServiceInvoker. Invoke method I am receiving an input string
parameter: xmlPayload.
Strings strRequestObjCl assName and strRequestPaylo adObjClassName will
be retrieved from .Config file and used to create appropriate instances
via Reflection. (I hard coded these values). Remember these have to
come from .Config file.

Newly created Payload object needs be initialized via
XMLSerializer.D eserialize method. I am first appending it
payloadObjectCo llection that is part of newly created Request object.
Here I start using "dynamic casting" (that is just my term I use to
explain the problem). And the problem is right there. I don't know what
the real type is when applying cast operator. It comes from the Type of
an instance created via Reflection.
Is it prohibited to use cast operation in this way. If yes, I need to
find another solution.

After (un)sucessful (!!!) deserialization this Request object should
then be added to a concrete object Requests (that I can instantiate
normally via new operator)

This is what I am trying to do:

string soaResponses ServiceInvoker. Invoke(string xmlPayload)
{
Assembly asm = Assembly.LoadFr om("InvocationM anager.dll");

string strRequestObjCl assName="soa.my company.soaRequ est"
object requestObj=asm. CreateInstance( strRequestObjCl assName,true);

string strRequestPaylo adObjClassName= "soa.mycompany. soaRequestPaylo ad"
object
payloadObj=asm. CreateInstance( strRequestPaylo adObjClassName, true);

((requestObj.Re flectedType)req uestObj).payloa d.payloadObject Collection.Add( payloadObj);

XmlSerializer xsPayloadObj = new
XmlSerializer(p ayloadObj.Refle ctedType);

StringReader srPayloadObj=ne w StringReader(xm lPayload);

((requestObj.Re flectedType)req uestObj).payloa d.payloadObject Collection[0]=
(payloadObj.Ref lectedType) xsPayloadObj.De serialize(new
XmlTextReader(s rPayloadObj));

....
}

I have at least one error for now.
The type or namespace name 'requestObj' could not be found (are you
missing a using directive or an assembly reference?

Once this is resolved I would expect to have an error for
(payloadObj.Ref lectedType) cast.

I tried also ((requestObj.Ge tType())request Obj).payload... .

I must have this working. Pleeeese help.
If not this way any other way would do. It has to be dynamic.

Thanks for help
Rad

Nov 12 '05 #1
0 1443

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

Similar topics

1
1303
by: Daniel | last post by:
how to load a C# dll from another C# assembly if the path of the loaded dll is not known until runtime
7
3414
by: Jack | last post by:
Hi, I am trying to test a sql statement in Access which gives me the error as stated in the heading. The sql statement is built as a part of asp login verification, where the userid and password are input in login screen. The password in the database is a number field. I am writing the dynamic sql statement as follows below. I believe I am going wrong in the password section of the code. I appreciate any help. Thanks. Regards.
5
5630
by: Randell D. | last post by:
Folks, I have a few <INPUT TYPE=TEXT> tags that are readonly if a specific field has no value... these work fine. However, I also have checkboxes which I would like to have as readonly, but the same code doesn't work - Can someone suggest a solution? This is sample code extracted from my original code: // Before other input tags determine if they are read only or not,
4
1450
by: ckpun1978 | last post by:
Hi, I am now writing a class using template. I run into a situation that, one of my member type is not unknown until run-time (but i dont' want to specify a template entry for it). How should I handle this? template <class T> class myfirst {
1
1308
by: | last post by:
This is a crosspost from a less-frequented (but more focused) asp.net group; I didn't receive an answer that worked. I'd like to get this form functional. Could someone help on what's probably a simple syntax issue? I've attempted my due diligence with the usual books and references...but I'm new to ASP.NET. Question follows: The Code Project has a nice article on making a "self configuring form mailer web control." Basically, you apply...
1
3878
by: mudasserrafiq | last post by:
I am using following asp file default.asp <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <META http-equiv=Content-Type content="text/html; charset=windows-1252"> <META content="0 Days" name=revisit-after> <META content=info@siderinternational.com name=email> <META content="Omer Safdar" name=author> <META content=MegaStudios.com name=publisher> <META content="Copyright ©2005 - MegaStudios.com" name=copyright> <SCRIPT...
6
2702
by: drsmooth | last post by:
is there a way to append a number to a variable name at runtime? like this i have 100 TImages i want to make an array with 1 pointer to each image i dont want to say: ptrs = timage1; ptrs = timage2;
2
4795
by: Joey | last post by:
I am querying a DataSet with LINQ. I am running into a problem when trying to construct my query because in the "from" clause I do not know the table name (range variable) until runtime. Possible table names might include "SomeTable1" or "SomeTable236" etc... Unfortunately when I try to use something like "from SomeTable + MyChangingNumber.ToString() in..." in my from clause it does not work. How can I set this up to use a range variable...
2
2353
by: Andy B | last post by:
I have the following listView control on a page: <asp:ListView ID="ListView1" runat="server" ItemPlaceholderID="PlaceHolder1"> <ItemTemplate> <dl> <dt>
0
8251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8182
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8352
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7178
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6115
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4085
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2614
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1496
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.