Visual Studio
web service proxy
WSDL file
software development
programming tutorial

Create a web service proxy in Visual Studio from a WSDL file

Codemia Knowledge Hub ·

To call a SOAP service described by a WSDL file from .NET, generate a client proxy instead of writing SOAP envelopes by hand. How you do it in Visual Studio depends on the project type: .NET Framework projects typically use Add Service Reference, while modern .NET projects use the WCF Web Service Reference provider or the dotnet-svcutil tool.

A WSDL file describes the service contract: operations, messages, bindings and endpoints.

Pick the tool for your project type

Use Add Service Reference when:

  • the project targets .NET Framework
  • the service is classic WCF or ASMX
  • you want Visual Studio to generate app.config entries automatically

Use WCF Web Service Reference or dotnet-svcutil when:

  • the project targets modern .NET
  • you want generated code that fits an SDK-style project
  • you want a repeatable command-line generation step

This matters because many older tutorials assume a .NET Framework project even when your solution isn't one.

Add Service Reference in a .NET Framework project

  1. Right-click the project.
  2. Choose Add > Service Reference.
  3. Enter the WSDL URL or local metadata address.
  4. Click Go.
  5. Choose a namespace such as MyApp.ServiceProxy.
  6. Confirm to generate the client classes.

Visual Studio creates:

  • proxy types
  • data contract types
  • endpoint configuration in App.config or Web.config

You then use the generated client like this:

csharp
1using System;
2using ConsoleApp1.ServiceProxy;
3
4class Program
5{
6    static void Main()
7    {
8        var client = new CalculatorClient();
9        var result = client.Add(2, 3);
10        Console.WriteLine(result);
11        client.Close();
12    }
13}

The actual client type name depends on the service metadata.

dotnet-svcutil for modern .NET projects

For SDK-style projects, dotnet-svcutil is often cleaner: it generates the proxy from a WSDL file or metadata endpoint without relying on older project-system assumptions.

Install it once:

bash
dotnet tool install --global dotnet-svcutil

Generate the proxy from a local WSDL file:

bash
dotnet-svcutil ./service.wsdl -n "*,MyApp.ServiceProxy"

Include the generated code in the project. The -n option maps the generated service types into the .NET namespace you choose.

Using the client is ordinary C#:

csharp
1using System;
2using MyApp.ServiceProxy;
3
4class Program
5{
6    static void Main()
7    {
8        var client = new CalculatorClient(CalculatorClient.EndpointConfiguration.BasicHttpBinding_ICalculator);
9        var result = client.AddAsync(5, 7).GetAwaiter().GetResult();
10        Console.WriteLine(result);
11    }
12}

Again, the exact class and endpoint names depend on the WSDL.

Generating from a local WSDL file

A .wsdl file on disk works as well as a live service URL, as long as:

  • the WSDL references any imported XSD files correctly
  • every related metadata file is reachable at its local path
  • you are prepared to override the service address in the metadata for the real environment

Many "failed to generate proxy" errors have nothing to do with Visual Studio. They come from incomplete metadata where the WSDL imports schemas that are missing locally. A WSDL file on its own is often not enough.

Binding and endpoint configuration

Generating the proxy is only half the job. The generated code is just a client stub, and it still needs working bindings, endpoint addresses and credentials. For a simple basic HTTP endpoint, the generated config often looks like this:

xml
1<system.serviceModel>
2  <bindings>
3    <basicHttpBinding>
4      <binding name="BasicHttpBinding_ICalculator" />
5    </basicHttpBinding>
6  </bindings>
7  <client>
8    <endpoint
9      address="http://localhost:5000/Calculator.svc"
10      binding="basicHttpBinding"
11      bindingConfiguration="BasicHttpBinding_ICalculator"
12      contract="ServiceProxy.ICalculator"
13      name="BasicHttpBinding_ICalculator" />
14  </client>
15</system.serviceModel>

If the proxy compiles but calls fail at runtime, check the binding and endpoint settings next.

When generation fails

Common causes:

  • the WSDL address is wrong or unreachable
  • imported schemas are missing
  • the service needs authentication or network access the development machine doesn't have
  • the metadata uses bindings your target framework or tool doesn't support

Try the command line with dotnet-svcutil or svcutil.exe; its error messages are often clearer than the Visual Studio dialog.

Avoid hand-editing generated code unless you must. Regenerating becomes painful once local changes are mixed into generated files.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design