5
Answers

Refering to a Webservice creates a new type

mr_bart_simpson

mr_bart_simpson

21y
1.7k
1
I'm trying to write a Client-Server App. The Server-Side functionality is implemented by a webservice that references a code library which is used by the client, too. This lib defines a struct that is used often on both sides... but when I define the struct as a result of a webmethod, update my binding to the webservice it results in a autogenerated class that is not directly castable to my original type! Anyone who knows how to avoid the problem? Bart Simpson
Answers (5)
0
sacresp
NA 458 0 20y
Just comment out the generated types in reference.cs And remember to add using YourNamespaceThatContainsTheLibrary
0
mr_bart_simpson
NA 16 0 21y
Well, in my opinion, the problem is that it generates the Type anyway. No matter, if it already has a direct reference to it or not. I tried it with just giving the Webservice no name while importing into VS.net, but what happend did not work: I got two (crashing) types with the same name, because the auto-generated one resists in the same namespace. When I gave a name to the webservice the new type get's its own namespace and that results in a different type for the framework. Maybe this is an bug in the importing tool, that generates the source, but I don't know, wether someone intenionally thought about that and the way I try to use it. Bart Simpson
0
spgilmore
NA 591 0 21y
That's a toughie. Sorry. I'm a little curious why it produces a type that is different than the original. I wonder if you're using a primitive type in your complex type that doesn't convert directly to an XML primitive type. Food for thought...
0
mr_bart_simpson
NA 16 0 21y
Wether or not this is a good feature, is a point you could argue about... Normaly it is very good, but in my special case it isn't. I'm using a class library both on client- and on serverside. But importing the webservice always generates new types, no matter wether the original type are already accesible or not. And so I alway have to map between types used in my library and the types that are automatically generated... Because I'm still developing the library, there are sometimes changes in the transmitted classes, and I' alway have to rewrite the conversion methods, too. The best way out that I found was using reflection to automatically do this job. But this only works with primitive types like int or string or something... Anny suggestions how to do better? Thx in advance Bart Simpson
0
spgilmore
NA 591 0 21y
That's one of the good things about Web Services. WSDL allows web service clients to figure out the types used in the server without knowing anything else about it. Your WSDL import tool reads the type definition from the WSDL document and generates the necessary types for you. Use the autogenerated type.