Problem with namespace

  • Thread starter Massimo Gentilini
  • Start date
M

Massimo Gentilini

I have a problem with namespace:

I've a class in a namespace

namespace.Foo

that's used in a web method

when I reference the web method from a web service the namespace changes
because of the wsdl compiler, so now my class, in the code using the web
service reference.cs becomes

webservicenamespace.Foo

Problem is that in my web method Foo I need to call the same web method Foo
on a different machine to create a sort of NLB scheme, but the web reference
I add need a webservicenamespace.Foo parameter while I have a namespace.Foo
instance.

Code is more or less like this
public void Do(Foo parameter) { // This is namespace.Foo
if(useNLB) {
WebService ws = new WebService()
ws.url = GetNLBUrl();
Do(Foo); // This instead needs webservicenamespace.Foo
}
else { ... perform operation }
}

Is there a way to accomplish this? Obviously casting the two classes do not
work...

Regards
Massimo
 
G

Greg Young

You would have to copy the data from one class to the other.
public void Do(Foo parameter) { // This is namespace.Foo
if(useNLB) {
WebService ws = new WebService()
webservicenamespace.Foo f = new webservicenamespace.Foo();
//copy properties of parameter to f
ws.url = GetNLBUrl();
Do(Foo); }
else { ... perform operation }
}

The other options (assuming the two foos are actually the same when it comes
to serialization) is that you can change the way your webproxy is generating
(to make it generate using namespace.Foo as a parameter as opposed to
creating its own). You could also use serialization to say a memorystream
(serialize namespace.Foo, deserialize as a webservicenamespace.Foo).
Generally the handling of the proxy generation is the preferred method here.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung
 
M

Marc Gravell

The WSDL-proxy and the actual class are simply not directly interoperable; I
guess you're either meant to be a client or a server here...
I don't like it as a solution, but you could try serializing
(xml-serializer) whichever Foo you have as xml (e.g. to a MemoryStream),
rewind the stream and then deserialize as the other Foo... since they have
the same structure it might just work - not very efficient though...

Marc
 
M

Massimo Gentilini

I don't like it as a solution, but you could try serializing
(xml-serializer) whichever Foo you have as xml (e.g. to a MemoryStream),
rewind the stream and then deserialize as the other Foo... since they have
the same structure it might just work - not very efficient though...

Thanks you both, I'm trying to evaluate how much this option will cost in
term of performance (having to do this stuff to create some king of NLB
based on my application and having a performance hit for language reasons
seems a little nonsense).

Ciao
Massimo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top