Add Service Reference does not generate proxy/client code in Visual Studio 2022

Chris Morelock 1 Reputation point
2022-10-28T13:40:06.813+00:00

Using Visual Studio 2022, the "Add Service Reference" (also "Update Service Reference" and "Configure Service Reference") does not generate the proxy/client code for a WCF service residing in a different project in the same Visual Studio solution. It creates a "References.cs" file, but this file is empty. I don't see any errors, it just doesn't work. It works fine if I use Visual Studio 2019.

The project where I am trying to create the proxy/client was created using the "WCF Workflow Service Application" project template. I tried creating a brand new project using this template and adding the proxy/client there, but I had the same problem. Interestingly, the "Add Service Reference" function works as expected, using Visual Studio 2022, if I do it in a console application project.

Both projects--the one where the WCF service resides and the one where I'm trying to create the client/proxy--are .NET Framework 4.8.

Any ideas about what the problem could be?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,544 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Jiayao Wu-MSFT 186 Reputation points Microsoft Vendor
    2022-10-31T06:12:35.557+00:00

    Hi @Chris Morelock ,

    As far as I can know, this is usually a code-gen problem caused by unresolvable type name collisions.

    If you right-click on your service references and click Configuration to uncheck "Reuse Types in Referenced Assemblies", that might solve your problem.

    If you're still using this feature, make sure you've cleaned up the name.

    feel free to contact me if have issues.

    Regards,
    Jiayao Wu

    ------------------------------------------------------------------------------------------------------------------------------------------------------

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Chris Morelock 1 Reputation point
    2022-10-31T17:26:04.543+00:00

    Hi @Jiayao Wu-MSFT ,
    Thank you for the reply. I have tried unchecking the "Reuse Types in Referenced Assemblies" box, but it doesn't resolve the problem. I have also tried to simplify the situation as much as possible, and I am providing steps to reproduce the problem below. Again, this works if I do it in VS 2019. It also works, in VS 2022, if I use a different combination of project types. It does not work if the project hosting the WCF Service is created using the "ASP.NET Web Application (.NET Framework)" project template and the project where the proxy/client is created is created using the "WCF Service Application" project template.

    Steps to reproduce Problem

    ------------

    1. In Visual Studio 2022, create a new project using the "ASP.NET Web Application (.NET Framework)" project template with the name "TestWCF3" using .NET Framework 4.8.  
      
    2. Add a new folder to the project named "Webservices"  
    3. Add to this folder a new item of type "WCF Service" with name "CarService.svc"  
    
    4. Add a new class file named "Car.cs" to the project with this code:  
    	  
    	public class Car  
    	{  
    	    public int Id { get; set; }  
    	    public string Make { get; set; }  
    	}  
    	  
    5. Modify the generated CarService interface to have only this "AllCars" method:  
    	  
    	[ServiceContract]  
    	public interface ICarService {  
    	    [OperationContract]  
    	    List<Car> AllCars();  
    	}  
    	  
    6. Modify the CarService.cs class to implement the ICarService interface like this:  
    	  
    	public class CarService : ICarService {  
    	    public List<Car> AllCars() {  
    	        return new List<Car>() {  
    	            new Car() {Id = 1, Name = "Ford"},  
    	            new Car() {Id = 2, Name = "Honda"}  
    	        };  
    	    }  
    	}  
    	  
    7. Build the project.  
      
    8. Add a new project to the solution using the "WCF Service Application" project template with the name "TestWCF3.Workflow" using .NET Framework 4.8.  
    	  
    9. Right-Click on the "References" item in the new "TestWCF3.Workflow" project and select "Add Service Reference…"  
      
    10. In the "Add Service Reference" dialog, press the "Discover" button; expand the "Webservices/CarService.svc" service and select "CarService"; change the Namespace to "CarClient"; and the press the OK button.  
    	  
    11. The files shown here are generated, but the "References.cs" file is empty.  It should contain the required proxy/client code.  I received no error messages at all.  
      
    10/31/2022  12:23 PM               391 CarService.disco  
    10/31/2022  12:23 PM             2,949 CarService.wsdl  
    10/31/2022  12:23 PM               846 CarService.xsd  
    10/31/2022  12:23 PM             2,488 CarService1.xsd  
    10/31/2022  12:23 PM               794 CarService2.xsd  
    10/31/2022  12:23 PM             1,461 configuration.svcinfo  
    10/31/2022  12:23 PM            19,810 configuration91.svcinfo  
    10/31/2022  12:23 PM               651 endpointConfigurationNameResolver.svcinfo  
    10/31/2022  12:23 PM                 0 Reference.cs  
    10/31/2022  12:23 PM             2,440 Reference.svcmap  
    			  10 File(s)         31,830 bytes