Peri
Peri

Reputation: 163

How to "Add Service Reference" in .NET Standard project

I would like to do "Add Service Reference" in .NET Standard project.(Visual Studio 2017)

I installed "System.ServiceModel.Http" and "System.ServiceModel.Security" on NuGet in order to make WCF access possible.

However, there is no "Add Service Reference" menu item in the .NET Standard project. How do I add a service reference?

It exists in the .NET Framework project but it does not exist in the .NET Standard project, so it is in trouble.

Upvotes: 16

Views: 26076

Answers (6)

greg
greg

Reputation: 117

This exercise is based on Use the WCF Web Service Reference Provider Tool

Environment:

I have consumed asmx web service, but the documentation said: its the same whit WCF service. I think it apply to all SOAP service.

  1. Add service reference (using WCF Web Service Reference Provider Tool).
  2. Add package references:

1) Steeps to add service reference:

Project> Add connected Service

Add connected service

Add WCF service Reference to Project.

Add WCF reference

Discover

Naming

Package

Upvotes: 3

Don B
Don B

Reputation: 917

These solutions didn't really work for me. I was using this with Unity 2019.1.10f and Visual Studio 2017. I found what you need to do is add the dll's that relate to WCF to your Unity project and then generate the service client proxy and bring that over to your scripts. Step by Step below.

  1. Create a new Unity 3D project, or open yours, then create a new folder under Assets called Plugins.
  2. Navigate to the installation folder of Unity (e.g. C:\Program Files\Unity\Hub\Editor\2019.1.10f1).
  3. From the installation folder, navigate to the the Editor\Data\Mono\lib\mono\2.0, in this folder you should find System.ServiceModel.dll, you need to copy this file into the Plugins folder created in step 1.
  4. Now generate the the service client proxy, you can do this in a few ways, one option is to use svcutil, for example run the command below in a VS command prompt to generate the client proxy class.

    svcutil -out:c:\temp\ClientProxy.cs https://[YourWebServiceDomain]/[Service].svc

  5. Copy the ClientProxy.cs file above into your project wherever you like under assets.

  6. Now add a new Monobehaviour script, something like WebClient.cs into your project. You'll need to attach this to some game object in your scene for the script below to run.
  7. Open up the WebClient.cs and add your code to connect to the new proxy service, example below.
using UnityEngine;
using System.ServiceModel;
using YourClientProxyNamespace;

public class WebClient : MonoBehavior
{
  void Start()
  {
    using (ProxyClient client = new ProxyClient(
        new BasicHttpBinding(BasicHttpSecurityMode.Transport),
        new EndpointAddress("https://YourWebServiceDomain/Service.svc")))
    {
      var response = client.DesiredMethod();

      // Do whatever with the response
    }    
  }
}

Upvotes: 1

eic
eic

Reputation: 51

Visual Studio 2017 Community v15.9.7

Solution Explorer -> Right click Dependencies -> Add Connected Service

ScreenShot:

Upvotes: 5

TPG
TPG

Reputation: 3219

Actually you can right click, go to "Add Connected Service", and then click on the "Microsoft WCF Web Service Reference Provider" and it should works the same as the "Add Services".

Upvotes: 0

Damo
Damo

Reputation: 447

I landed here hoping to solve a slightly different problem... but to maybe answer your question;

I had to update VS2017 to the latest version (I'm now on 15.5.2), then; Right-Click the project >> Add >> Connected Service, then click "Microsoft WCF Web Service Reference Provider". The provided dialog is very similar to that of the Framework "Add Service Reference" option.

It's the same "Add" menu you would use if you were to add a new class etc...

This was added in verion 15.5. See WCF on github for more info.

Upvotes: 6

Vondella21
Vondella21

Reputation: 89

you can add it manually by dragging your service into bin directory

Upvotes: -7

Related Questions