Returning a custom class object

This is my first time creating a web service ... so I'm hoping this is an easy questionSmile

Basically, I have a normal windows class (call it myNamespace.myService). This class has a method that returns a serializable class object (call it myNamespace.myClass).

Now, I've written a seperate web service that's really just a thin wrapper around myNamespace.myService. (I call the web method, and behind the scenes it calls into myNamespace.myService, and returns an instance of myNamespace.myClass).

Now, all that works ... sort of - the problem is the return parameter. Instead of coming back as a 'myNamespace.myClass' object, it comes back as a 'myNewNamespace.localhost.myClass' object!

So how do I fix this? Or what am I doing wrong?

How do I get my web service to actually return a myNamespace.myClass object?

[898 byte] By [Glenfar] at [2008-2-12]
# 1
Well, so much for the hope of an easy question ... Sad

I've found a way around it ... not one I particularly like, but it works. I just wrote another wrapper class, this one around the web service. So it makes the web call, copies the members from the return class into a new myNamespace.myClass object, and returns that.

At least it means the calling projects don't need to worry about the web stuff at all - to them it's just a straight call to a windows class. That part I like ... but having two wrappers around my service, especially where one of them needs to know all the details of the underlying class object - that I don't like.

Anyway, it does work - so unless someone out there has another suggestion ...

Glenfar at 2007-9-8 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...
# 2
When you add a web reference to a project, you can control the namespacing of the generated code. Here's how:

1) Select the project in the solution explorer and click the "Show All Files" button at the top of the solution explorer (or select Show All Files from the Project menu). You'll notice that all of your web services have + next to them in the solution explorer.

2) Expand the web reference branch and you will see a "Reference.map" file. Click on that file and open the properties window.

3) There is a property called "Custom Tool Namespace". Enter your desired namespace there (e.g. myNamespace), and all of the generated code will use that.

4) For good measure, I usually rebuild the project to make sure the new code gets generated and compiles without any name collisions.

hth

Todd Gray

Todd.Net at 2007-9-8 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...
# 3
Thanks for the attempt ... but it doesn't work.

When compiling I get a bunch of warnings about the class being defined in multiple places, although it does compile. However, when I actually try to call it, I just get back an error: "There was an error generating the XML document".

Glenfar at 2007-9-8 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...
# 4
I am unable to reproduce the error that you described. On VS 2005 Beta2 I can successfully follow the steps to update the namespace for the web service proxy types. Please post your code or provide more detailed steps on how to reproduce this error.

Thanks.

Daniel Roth

DanielRoth at 2007-9-8 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...

.NET Development

Site Classified