Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WCF MSMQ
Unable to cast object CPerson to ServiceReference.CPerson
 
CPerson is defined in its own assembly and is referenced throughout my application.
 
This is an extract form how my the contract on my Central Message Distribution Service is defined:
 
    [ServiceContract(
    Name = "CMDS_QueuedService"
    )]
 
    public interface ICMDS_QueuedService
    {
        [OperationContract(IsOneWay = true)]
        void DistributeData(short arg_Installation_ID, CPerson arg_DataRow);
    }
 
    public class cCMDS_Contract : ICMDS_QueuedService
    {
        [OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
        public void DistributeData(short arg_Installation_ID, CPerson arg_DataRow)
		{
		//Do Stuff
		}
	}
 
CPerson in the DistributeData arguments is the class defined in my standard assembly (Db_person.CPerson), but then I add a service reference to my Local Messasage Handler, it's type is now ServiceReference.CPerson and a cast will not work.
 
Considering this quote from Andrew Troelsen: "The ability to serialize objects is critical when you want to copy an object to a remote machine using various remoting technologies such as Windows Communication Foundation."
 
Are my options some form of copy constructor, am I looking at serialize / de serialize as above, or something else that I have not even considered?
Posted 10-Jan-13 8:37am
Ger Hayden25.8K
Comments
Ger Hayden at 11-Jan-13 5:13am
   
I think I have it solved by serializing the class. I need to iron out a few things before adding a solution.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I expected the answer to be in using SoapDataFormatter or DataContractSerializer to a memory stream would be the solution and deserialize on the other side.
 
But no. If the service wants to do anything with the stream, the type e.g. DB_Person.CPerson trips it up - and yes I remembered to reset the stream position.
 
The solution that I managed to implement involved reading the stream into a byte array, passing that over on the queue to the service, rebuilding the stream and deserializing it.
 
I will not post code unless asked because while it works, its not a solution I am particularly proud of.
 
(This post will close the 'question') and hopefully provide some guidance to anyone in a similar bind)
 
I am also going to do a test where the stream is passed in to the service and rather than deserializing it, the service relays it to other subscribed clients to see if they can act on it...
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 381
1 Sergey Alexandrovich Kryukov 265
2 Praneet Nadkar 237
3 Marcin Kozub 225
4 /\jmot 189
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100