Groups | Blog | Home
all groups > dotnet web services > may 2006 >

dotnet web services : Generated proxy class conflicts with custom class


Fabio
5/25/2006 11:33:01 PM
An ASP.NET 2.0 web site contains a web form and a web service. The web form
consumes the web service. There is a Book class in the App_Code folder. The
web service exposes a method that returns a Book object. The consumer expects
to receive a Book object. However the Book generated proxy class conflicts
with the Book class in the App_Code folder. (See also the following code.) I
bet there is an easy way to solve this, but I have no idea...

Thanks,
Fabio


// App_code/ClassLibrary.cs
namespace ClassLibrary
{
public class Book { ... }
}


// WebService.asmx
namespace WebService
{
[WebService(Namespace = "...")]
public class BookWebService : WebService
{
[WebMethod()]
public ClassLibrary.Book GetBook() { ... }
}
}

// Consumer.aspx
public partial class Consumer : Page
{
protected void Button1_Click(object sender, EventArgs e)
{
WebReference.BookWebService ws =
new WebReference.BookWebService;

// The following statement does not compile
// Error: Cannot implicitly convert type 'WebReference.Book' to
'ClassLibrary.Book'
ClassLibrary.Book book = ws.GetBook();
}
}


Pierre
5/26/2006 3:07:28 AM
Hi Fabio,

If I got it right 'ClassLibrary.Book' is the same as
'WebReference.Book' but in a different namespace.

If they do the same why not doing:
WebReference.Book book = ws.GetBook();

And stop using the ClassLibrary.Book (as you shouldn't need it)?

I read your e-mail quite fast so I might have not got your issue right.

regards,

Pierre
Fabio
5/26/2006 3:35:01 AM
Hi Pierre,

Thanks for your answer.

You did read my message carefully enough. I did not make myself clear
enough. The consumer has methods that require ClassLibrary.Book parameters.
Please, consider the following code (which I should have posted before).

// Consumer.aspx
public partial class Consumer : Page
{
protected void Button1_Click(object sender, EventArgs e)
{
WebReference.BookWebService ws =
new WebReference.BookWebService;

private void ReadBook(ClassLibrary.Book book) { ... }

// The following statement does not compile
// Error: Cannot implicitly convert type 'WebReference.Book' to
'ClassLibrary.Book'
ReadBook(ws.GetBook());
}
}

Furthermore, since WebReference.Book is generated based on the WSDL, the two
classes are not the exactly the same!

Regards,
Fabio


Fabio
5/27/2006 7:38:01 AM
Hi Gaurav,

That was exactly my (temporary) solution, because I had no time to look for
a better one. If I find one, I will let you know. :)

--
Fabio Scagliola
http://fabioscagliola.com



[quoted text, click to view]
Gaurav Vaish (EduJini.IN)
5/27/2006 7:31:22 PM
[quoted text, click to view]

The proxy class has automatically generated the class WebReference.Book from
the WSDL (Schema section)
You that class. Forget about ClassLibrary.Book. Pierre is correct.. :-)

If you require to work with ClassLibrary.Book in ReadBook, overload it... or
you may want to do is as follows (useless thing, probably);

public ClassLibrary.Book
{
public ClassLibrary.Book ToCLBook(WebReference.Book original)
{
ClassLibrary.Book retVal = new ....
-copy-all-values-
return retVal;
}
}


--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------

Gaurav Vaish (EduJini.IN)
5/28/2006 12:05:43 AM
[quoted text, click to view]

Would be looking forward to eagerly...
However, I think using the proxy-generated classes should always suffice.


--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------

AddThis Social Bookmark Button