views:

78

answers:

2

I have a C# project which has many web references to a third party product. All of these web service calls use a 'user context' class. So each web service accepts the exact same XML snippet.

Currently I have to keep many of these 'user context' objects around as I hit all the different web service calls. The generated 'user context' class is the exact same but just put in different .NET namespaces (the XML namespace is the same).

I would like to be able to have only one of these instances passed around. How could I do that?

I am using Visual Studio 2010 and using the generated class by adding a WebReference. I'm not opposed to using some other framework or mechanism. I had even thought of rolling my own code, but there are many WebServices (each with many web methods) that I will need to use.

Update: I originally added these by adding a Web Reference, I will now be adding them as a Service Reference. The web services themselves are exposed through InterSystems Caché and I haven't looked into how well they conform to WS-I.

+1  A: 

Not sure about VS 2010, but in 2008 there was an option "reuse types in referenced assemblies" in the service reference adding wizard which does just what you need. In order to have the same type in all web references create an assembly, put those type definition there, reference it from your project and then add web references you need.

Konstantin Oznobihin
I hadn't looked at those options before, so I tried them out and read about them. I do not think this is what will work for me. From what I've read this typically pertains to types already defined in a shared class library (which I do not have).These types are part of the web services themselves and not any shared library that I have written or have access to. Please enlighten me if I am wrong in the functioning of this option.
Chad Gorshing
You are quite right about this option, but you miss one thing: you can create necessary shared class library by yourself. It's very easy actually:1. Create class library project2. Add web reference to any of your services with types you'd like to share setting access level to public3. Reference this class library in your project.And that's all. All web references you'll add to your project from now on will use types from your class library.
Konstantin Oznobihin
A: 

I resolved a problem like this by using only one class and converting the object with XML serialization/deserialization. But still it's not the perfect solution.

remi bourgarel