ASP.NET 5 add WCF service reference

In Visual Studio 2015 Preview (Pre Release), how can I add a service reference for a WCF service?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Currently, this is a fairly involved process as the tooling does not seem to support much in the way of generating WCF client code or automatically map from config files. Also, as dotnetstep has pointed out, the ASP.NET team has not ported System.ServiceModel to 5 yet (or provided an alternative for WCF clients yet). Nonetheless, we can use a code-based approach to create a client proxy and use svcutil to generate our service reference classes.

Solution Prerequisites

For this example, I will assume you are locally hosting a service at http://localhost:5000/MapService.svc that implements an IMapService contract. Also, we will call the project that is going to contain the service proxy MapClient.

Your project.json should look something like:

    "commands": {
        "run": "run"
    "frameworks": {
        "dnx451": {
            "dependencies": {
                "Microsoft.AspNet.Mvc": "6.0.0-beta2"
            "frameworkAssemblies": {
                "System.ServiceModel": ""

Generate the Service Reference Classes

First, let’s create a folder, Service References, in the MapClient project.

Next, open up Developer Command Prompt for VS2015 and navigate to your MapClient project directory:

cd "C:UsersyouraccountDocumentsVisual Studio 2015ProjectsMapClientsrcMapClient"

Make sure MapService is running and run the following command:
svcutil /language:cs /out:"Service ReferencesMapServiceReference.cs" http://localhost:5000/MapService.svc

That should generate two files, output.config and MapServiceReference.cs.

Create a code-based client proxy

Since there is no way to automagically map endpoint and binding configuration from a config file to your ClientBase currently in ASP.NET 5, the output.config isn’t of much use to us. You can remove it.

Instead, let’s create a client proxy in the code:

using System.ServiceModel;

namespace TestWCFReference
    public class Program
        public void Main(string[] args)
            var endpointUrl = "http://localhost:5000/MapService.svc";
            BasicHttpBinding binding = new BasicHttpBinding(); 
            EndpointAddress endpoint = new EndpointAddress(endpointUrl);
            ChannelFactory<IMapService> channelFactory = new ChannelFactory<IMapService>(binding, endpoint);
            IMapService clientProxy = channelFactory.CreateChannel();

            var map = clientProxy.GetMap();


Now you can use the clientProxy instance to access any Operation Contract in IMapService.

As a sidenote, it would probably be better architecture to create a key:value config file that stores your binding and endpoint configuration and use the Microsoft.Framework.ConfigurationModel.Configuration object to populate your ChannelFactory so you can keep your service configuration out of your code, but hopefully this example will get you started.

Method 2

There is a new Visual Studio extension which allows you to add and use service references like in previous versions. It is also compatible with the new CoreCLR, I have just tested it.

Method 3

Currently there is no tooling available for this and possible reason for this System.ServiceModel which is not available in asp.netcore5.

If you decided to use 5 the you can do following thing as of now to use WCF service ( I am using Visual Studio 2015 CTP 5 for this answer)

In VS 2015 CTP 5 , it allow us to add reference of regular class library.

  1. Create WCF service.
  2. Create Regular Class Library ( I choose .NET Framework 4.6)
  3. After that I added WCF service reference to ClassLibrary.
  4. Add ClassLibrary as a Reference to 5 website.
    ( As the CoreCLR framework does not support System.Service Model so I removed that from project.json) Framework part of project.json.
    "frameworks": {
    "aspnet50": {
        "frameworkAssemblies": {
             "System.ServiceModel": ""
        "dependencies": {
             "ClassLibrary2": "1.0.0-*"
  5. Now if you look at classlibrary project it contains app.config file.
  6. Copy that file and put it in wwwroot folder of website project (vnext)
  7. rename it to web.config.

Now run your application.

Method 4

Edit: The new extension for adding a connected service as posted in other answers still did not work for me, but I found another working configuration, though it requires you don`t use dnxcore50:

  • Have a class library holding the service reference (choose a framework <= aspnet5 used one, e.g. dnx451)
  • Reference that one into your aspnet5 with right clicking on references (will create all the wrap stuff)
  • Have Service model and needed serialization dll in “framework” section of project.json (dnxcore need to be removed)
         "dnx451": {
           "dependencies": {
            "YourClassLibWillAppearHere": "1.0.0-*" // after you reference it
           "frameworkAssemblies": {
            "System.ServiceModel": "",
            "System.ServiceModel.Http": "",
            "System.Runtime.Serialization": ""

You should be able to do where u need it:

using YourNameSpace.ServiceReference

Old Answer:

this worked for me:

I followed both the instructions at the same time provided under known issues for beta4 (find in page “WCF”) at this link:

so my steps where:

  1. added service reference to another project (class library or windows 8.1 univ app as advised)
  2. copied the reference class to the ASP.NET 5 project
  3. copied the whole


    from app.config to web.config

  4. copied all those missing dependencies list from the link above in project.json, under common dependencies, leaving alone the specific frameworks ones (trying to reference the dotnet4.6 class library as an aspnet framework dependency gave many missing types in that framework)

"dependencies": { >> here << }

"frameworks": {
    "dnx451": { },
    "dnxcore50": { }

Method 5

Another potential way of doing this that has worked for me is to simply add a dll project to the solution and add the service ref here as you normally would – include the dll in the MVC project and ref for the services.

You just need to copy the contents of app.config to the mvc projects own app.config – yes, app.config, not web.config.


Method 6

If you have encountered with System.ServiceModel after WCF service is added with .NET 5. You can delete the Assemblies System.Servicemodel and add following packages with version 4.4.4 . This worked for me.


All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x