3

I am trying to run a simple webservice for random numbers using c#. When running the program, it opens a webpage instead of running the WCF Test Client. I have a VS 2019 installed. I also see the wcftestclient.exe in the folder.
Please help me if I am missing any setup/ where to enable it so that it runs in the wcftestclient.
Thanks in Advance.

  1. I tried to as /client:"wcftestclient.exe" in application arguments in project properties -> debug

  2. added project extensions as below in .csproj,

<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
        <TargetFramework>netcoreapp2.1</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.App" />
        <PackageReference Include="Microsoft.AspNetCore.Razor.Design" 
                          Version="2.1.2" PrivateAssets="All" />
    </ItemGroup>

    <ProjectExtensions>
        <VisualStudio>
            <FlavorProperties GUID="{123c5851-25df-10da-9384-00011b846f00}">
                <WebProjectProperties> 
                    <EnableWcfTestClientForSVCDefaultValue>
                        True
                    </EnableWcfTestClientForSVCDefaultValue>
                </WebProjectProperties>
            </FlavorProperties>
        </VisualStudio>
    </ProjectExtensions>
</Project>
  1. tried to disable launch browser in proj properties-> debug
namespace SampleWebServiceasp
{
    class RandomNumberGeneratorService
    {
        public NumberModel GetRandomNumbers()
        {
            var random = new Random();
            var numberobject = new NumberModel
            {
                RandomNumber1 = random.Next(-500, 5000),
                RandomNumber2 = random.Next(-500, 5000),
                RandomNumber3 = random.Next(-500, 5000)
            };
            return numberobject;
        }

    }
}
namespace SampleWebServiceasp.Models
{
    public class NumberModel
    {
        public int RandomNumber1 { get; set; }
        public int RandomNumber2 { get; set; }
        public int RandomNumber3 { get; set; }
    }
}

Expected to run it in wcftestclient and it opens a webpage

barbsan
  • 3,418
  • 11
  • 21
  • 28
Sneha
  • 27
  • 3

2 Answers2

3

Before you start running or debugging select the service svc.cs file in "Solution Explorer"

Solution Explorer

As indicated in the notes for the default wcf template

// NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.

Rey
  • 186
  • 5
3

For me, "Windows Communication Foundation" component was not installed in Visual Studio. Installing it solved.

Daniel Genezini
  • 694
  • 9
  • 12