Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting type from a WCF service

I'm sure this must be a pretty common problem. I have two WCF services, that basically expose standard access and admin access to one larger service.

There is a similar method Foo on each service. Foo takes an argument of type TemplateInfo which is defined in my service.

On my client I have a reference to Client and AdminClient. Client.Foo(TemplateInfo) expects Client.TemplateInfo while AdminClient.Foo(TemplateInfo) expects AdminClient.TemplateInfo. I know that once the service is reached Client.TemplateInfo and AdminClient.TemplateInfo are the same thing.

I'm trying to figure out how to instantiate TemplateInfo and/or cast it to work with both client and admin methods. There is a decent amount of code to create this object so I was hoping not to duplicate that for each type.

The types are defined in shared assemblies and I am "Reusing types" in my proxy. But I get the two different types because I have two service references.

It would be great to do something like (AdminClient)TemplateInfo, but perhaps I'll create a clone method to convert the types.

like image 894
earthling Avatar asked Mar 08 '11 19:03

earthling


1 Answers

There's no way to do that. They are different types.

You can put that type into a class library that is references by both services and by the client. You can tell "Add Service Reference" to reuse types (it's the default), and then it will be the type from the class library that is used.


Note that the client application will also need to reference the same class library as the two services.

like image 169
John Saunders Avatar answered Sep 27 '22 17:09

John Saunders