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.configentries 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
- Right-click the project.
- Choose
Add > Service Reference. - Enter the WSDL URL or local metadata address.
- Click
Go. - Choose a namespace such as
MyApp.ServiceProxy. - Confirm to generate the client classes.
Visual Studio creates:
- proxy types
- data contract types
- endpoint configuration in
App.configorWeb.config
You then use the generated client like this:
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:
Generate the proxy from a local WSDL file:
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#:
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:
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.
Related reading
- Creating a JSON response using Django and Python
- Crop image to bounding box in Tensorflow Object Detection API
- Cross Account Alias Records
- Cross origin requests are only supported for HTTP. error when loading a local file
- Creating a blocking QueueT in .NET?
- Creating a comma separated list from IList<string> or IEnumerable<string>
- CSV API for Java
- Curl to get Rabbitmq queue size

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.