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
includes a method that require a Book parameter. However the Book generated
proxy class conflicts with the Book class in the App_Code folder. Please,
consider 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;
private void ReadBook(ClassLibrary.Book book) { ... }
// The following statement does not compile:
// Cannot implicitly convert type 'WebReference.Book' to 'ClassLibrary.Book'
ReadBook(ws.GetBook());
}
}
Hello Fabio,
Thank you for your post!
When adding a Web Reference in Visual Studio, it uses the Web Services
Description Language tool (Wsdl.exe) internally to generate proxy code for
XML Web services. The generated types that are used in the proxy class are
based on the contents of the WSDL document that describes the XML Web
service. However, the generated types might not be what you want nor what
you expect. If you do not want to use the generated types, you can change
the generated types to more desirable types. To get the appropriate object
type, you can open the file that contains the generated proxy classes,
manually change the generated method paremeter, and then return types to
the appropriate object types.
In Visual Studio 2005, the generated proxy class source file is not
accessible by default, it's directly compiled into an assembly. So we must
manually generate the proxy class file using Wsdl.exe and modify the class
file later.
So regarding your issue, we can:
1) Remove existing Web Reference;
2) Open "Visual Studio 2005 Command Prompt", run "wsdl.exe /language:cs
/namespace:WebService http://localhost:12345/WebSite1/BookWebService.asmx",
this will generate 'BookWebService.cs' in current folder
3) Copy this file to your project and manually modify related method
parameter or return type to 'ClassLibrary.Book'.
Hope this helps. If there's anything unclear, please feel free to post here.
Regards,
Walter Wang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights
Fabio - 29 May 2006 08:15 GMT
Hello Walter,
Thank you for your reply!
I was afraid that manually editing the generated proxy class(es) would have
been the only solution, because I will have to manually update them in case I
update the web service.

Signature
Fabio Scagliola
http://fabioscagliola.com
Walter Wang [MSFT] - 29 May 2006 10:11 GMT
Hi Fabio,
Thank you for your update. Have a nice day!
Regards,
Walter Wang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights
Hiren - 14 Sep 2006 13:56 GMT
Hi Walter,
I was facing the same issue, however, since i carried out the steps
mentioned before (placing the manually generated proxy.vb file in the
project), am getting several Error messages stating that various classes are
ambigious in the namespace of the generated proxy class.
e.g. "'GetOtherSystemsCompletedEventArgs' is ambiguous in the namespace
'dmWebRef'"
- Is there any particular area where we need to add the manually generated
proxy class?
Thanks in advance
- Hiren.
- Is there any other setting that needs to be performed for the same?
> Hi Fabio,
>
[quoted text clipped - 10 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights