FIX: Error Message When You Add a Web Reference to the Same Web Service More Than Once (311922)



The information in this article applies to:

  • Microsoft Visual C++ .NET (2002)
  • Microsoft Web Services (included with the .NET Framework 1.1)
  • Microsoft Web Services (included with the .NET Framework) 1.0

This article was previously published under Q311922

SYMPTOMS

When you add a Web reference to the same Web service more than one time in a Managed C++ application, you receive a compiler error message similar to the following:
c:\My Samples\MCTestClient\WebService.h(4) : error C3846: 'Service1' : cannot import symbol from 'c:\My Samples\MCTestClient\Service1.dll': as 'Service1' has already been imported from another assembly 'Service11.dll' c:\My Samples\MCTestClient\WebService.h(3) : see declaration of 'Service1'

RESOLUTION

If you used the Add Web Reference Wizard to add a Web reference, make sure that you delete the .cs, .wsdl, .dll and .h files (usually called Service1.cs, Service1.wsdl, Service1.dll, and Webservice.h) that are generated by the wizard from both the solution and physical file systems. Also, be sure to delete the Service1.dll file from the Debug/Release directory. Then, do either of the following:
  • Use the wizard again to add the Web reference. Repeat the method described at the beginning of the "Resolution" section of this article every time that you make a change to the Web service and want to use it in your client application.

    -or-
  • Use the Web Services Description Language tool (Wsdl.exe) to manually generate the client proxy class and generate an assembly. Then, add a reference to this assembly. Additionally, add references to the System.dll and System.Web.Services.dll files. When you run the following code from the command line, you generate the Service1.cs and Service1.dll files:
    wsdl http://localhost/WebSvc1/Service1.asmx //This would generate client proxy class source in C#..
    csc /t:library Service1.cs //This would generate the assembly that you can add a reference to.
    					

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft Visual C++ .NET (2003).

MORE INFORMATION

Steps to Reproduce the Problem

  1. Create a default C# Web service, uncomment the HelloWorld Web method, and then build the project.
  2. Add the Web reference that refers to the Web service (that you created in step 1) to a Managed C++ application.
  3. Include the generated proxy header file.
  4. Instantiate the Web service class, and then call the HelloWorld Web method.
  5. Add a new Web method (for example, HelloWorldNew), and then build the Web service.
  6. Add the Web reference to the Web service.

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MinorLast Reviewed:7/24/2003
Keywords:kbfix kbbug kbCompiler kberrmsg kbManaged KB311922