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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With