How to create a Web Service Project - Server, Client in C# - Some questions

Markus Freitag 3,786 Reputation points
2022-01-13T10:49:04.92+00:00

Hello,
I make a WebServer with this instruction.
how-to-create-a-web-service-project-in-net-using-visual-studio

Was ok. It is running
http://localhost:52683/WebService.asmx

To make it work I had to turn on the IIS.
How can I make the server active without VisualStudio?
164733-webservice-running-without-visualstudio.png

After that I created a WSDL file
and creates a proxy class.

C:\Users\freitag\source\repos\WebServiceProject>wsdl /par Test.wsdl
Microsoft (R)-WSDL-Hilfsprogramm (Web Services Description Language)
[Microsoft (R) .NET Framework, Version 4.6.1055.0]
Copyright (C) Microsoft Corporation. All rights reserved.
Datei 'C:\Users\freitag\source\repos\WebServiceProject\WebService.cs' wird geschrieben

C:\Users\freitag\source\repos\WebServiceProject>

Is this way right?

Then a C# client and I can call the functions. The question is how can I start the server without Visual Studio so I can test the client.

Can I also write a function that returns a json object. Do you have an example for this?

private void Form1_Load(object sender, EventArgs e)  
        {  
            using (WebService testClient= new WebService())  
            {  
                string test1 = testClient.HelloWorld();  
  
                List<int> lstTest = new List<int>();  
                lstTest.Add(7);  
                lstTest.Add(7);  
                lstTest.Add(7);  
                lstTest.Add(7);  
                int result = testClient.Add(lstTest.ToArray());  
            }  
        }  

164727-webservice-1.png

164734-webservice-2-wsdl.png

Could I also implement an ASMX file in the client? Do I necessarily need a WSDL file?

164742-webservice-cs.txt

Internet Information Services
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,210 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,312 questions
Windows Server Management
Windows Server Management
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Management: The act or process of organizing, handling, directing or controlling something.
422 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sam Wu-MSFT 7,041 Reputation points Microsoft Vendor
    2022-01-17T10:06:03.36+00:00

    @Markus Freitag

    This problem occurs because the website doesn't have the Directory Browsing feature enabled. Also, the default document isn't configured. To resolve this problem, use one of the following methods:

    Method 1: Enable the Directory Browsing feature in IIS

    1. Start IIS Manager. To do it, select Start, select Run, type inetmgr.exe, and then select OK.
    2. In IIS Manager, expand server name, expand Web sites, and then select the website that you want to change.
    3. In the Features view, double-click Directory Browsing.
    4. In the Actions pane, select Enable.

    Method 2: Add a default document

    1. Start IIS Manager. To do it, select Start, select Run, type inetmgr.exe, and then select OK.
    2. In IIS Manager, expand server name, expand Web sites, and then select the website that you want to change.
    3. In the Features view, double-click Default Document.
    4. In the Actions pane, select Enable.
    5. In the File Name box, type the name of the default document, and then select OK.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. AgaveJoe 26,146 Reputation points
    2022-01-13T11:34:47.267+00:00

    How can I make the server active without VisualStudio?

    I assume you want to publish to local IIS and you have installed IIS Manager.

    First create a publish profile for your ASMX service.

    • Create a WebService folder in C:\inetpub\wwwroot using Windows Explorer.
    • In visual Studio right click the WebService project and select publish.
    • Select the publish to a local folder option and click next
    • Enter C:\inetpub\wwwroot\webservice (the folder you created above) as the target folder and click next.
    • Click publish.

    Open IIS and create a new application.

    • Open IIS Manager (start -> run -> inetmgr)
    • Expand the computer name
    • Expand sites
    • Expand Default Web Site
    • Right click "WebService" (the folder you created above)
    • Select "Convert to Application"
    • Click "Ok"

    Open your browser and enter "http://localhost/WebService/WebService.asmx"

    You can create a Service Reference from Visual Studio which is more convenient than wsdl.exe. wdsl.exe works fine but it's an older utility.

    I think it is important to mention that you tagged this post as ASP.NET Core and this question is ASP.NET not Core. Secondly, ASMX is a very old technology. If you need a JSON response then create a Web API project.

    Lastly, creating an IIS application is not required. Visual Studio can run multiple projects. Simply right click on the solution file in Visual Studio solution explorer and select properties. Configure the start up options.

    1 person found this answer helpful.

  2. Limitless Technology 39,396 Reputation points
    2022-01-18T08:25:26.69+00:00

    Hi there,

    You can host the web application on your local machine, you will need to set up IIS and configure it to do so. Then you would publish the web application to IIS.

    By default, IIS 7.5 is not installed on Windows Server. You can install IIS 7.5 IIS by using the Add Roles Wizard in Server Manager or by using the command line.

    Installing IIS 7.5 on Windows Server 2008 R2
    https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-r2-and-2008/cc771209(v=ws.11)

    ---------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer--

    1 person found this answer helpful.
    0 comments No comments