Generated proxy class conflicts with custom class
|
| Generated proxy class conflicts with custom class | 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();
| | 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
| | > // The following statement does not compile > // Error: Cannot implicitly convert type 'WebReference.Book' to > 'ClassLibrary.Book' > ReadBook(ws.GetBook()); > } > }
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 -------------------
| | 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
"Gaurav Vaish (EduJini.IN)" wrote:
> > // The following statement does not compile > > // Error: Cannot implicitly convert type 'WebReference.Book' to > > 'ClassLibrary.Book' > > ReadBook(ws.GetBook()); > > } > > } > > 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 > -------------------
| | > 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. :)
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 -------------------
|
|
|
|
|
 | Members Area | |
|
 | Last Web Marketing |
|
|
|
|
 | Last Programming Tips |
|
|
|
|
 | Last News |
|
|
|
|
|
|