SOAP Services

SOAP is an XML-based protocol that lets you exchange info over a particular protocol (can be HTTP or SMTP, for example) between applications.
It stands for Simple Object Access Protocol and uses XML for its messaging format to relay the information.


SOAP is an XML based protocol that allows applications to exchange information over http.
It is a communication protocol
It is platform independent
It is based on XML, HTTP and SMTP
It is language independent


Any soap message can contain an optional header, which might contain additional information not strictly related to the method being called.
For example a client might use the header to send its credentials so that the web service can record who accessed its methods and when.
SOAP is the only protocol that support objects and structures.
The only requirement for an object fed to (or returned) is that it must be serializable.
SOAP is also the only protocol that supports output arguments using ByRef.



web.config Changes

All three protocols are enabled by default although you can disable one or more of them by editing your local web.config file.
In a production web service you might want to drop all the add tags except the SOAP one.

<configuration> 
   <system.web>
      <webServices>
         <protocols>
            <add name="HttpSoap" />
            <add name="HttpPost" />
            <add name="HttpGet" />
            <add name="Documentation" />
         </protocols>
      </webServices>
   </system.web>
</configuration>


WSDL

This is an XML based language for describing web services.
This is used to describe the web service, the description of the methods provided (Web Service Description Language)
It specifies the location of the web service and the operations that is exposes


Different Component

A WSDL has several different components
definitions
types - the data types used by the web service should use XML schema syntax


message - the messages used by the web service


portType - the operations performed by the web service and the messages that are involved
There are four different types

One-Way - can receive a message
Request-Response - can receive a message and return a response
Solicit-Response - will send a request and wait for a response
Notification - can send a message and not wait for a response

binding - the communication protocols used. Defines the message format and protocol details
Binding to SOAP

binding element - this has two attributes (name - any name to describe the binding) (type - points to the port for the binding)
soap:binding element - this has two attributes (style - either "rpc" or "document") (transport - which SOAP protocol to use, typically http)
operation element - defines each operation

service - makes it possible to group several definitions together into a single WSDL document



SOAP Service with Web Reference

Added in .NET 1.1
This supports any service that implements WS-I Basic Profile 1.1
This uses the ASMX communication stack on the clients side
This was for the original ASP.NET web services which used System.Xml.Serialization.XmlSerializer
This only supports BasicHttpBinding


This is a wrapper over wsdl.exe and creates a client proxy



Add a Web Reference
This dialog box lets you select a web service from those registered in a Universal Description, Discovery and Integration directory.
UDDI directories are a bit like the web services yellow pages in that they list XML web services distributed across the Internet.
Visit www.uddi.org for more details.
Type the path to your .asmx file on your local machine amd press Enter.
The left pane will display a description page associated with the web service.
The right pane contains additional links to view the WSDL contract.
Go ahead and add the reference.


After any changes to the web service you should rebuild the proxy class.
The easiest way is to select the service and select "Update Reference".


Adding a Web reference to your project for the Web service does this by generating a proxy class that interfaces with the Web service and provides a local representation of the Web service.


Example

Open Visual Studio 2022 as Administrator.
New Project, Windows Forms App (.NET Framework) C#
Create folder C:\temp\winforms\


Create new project,
Press Next


Project name - WebServicesProject
Location - C:\temp\winforms
Framework - .NET Framework 4.8


Add a TextBox to the windows form - name - myTextBox
Add a Button to the windows form - name - myButton
Double click the button to add the event handler


Right click on the project and select
Add > Service Reference
press Advanced
press Add Web Reference


Add the following URL and press GO

dneonline.com/calculator.asmx?wsdl 

change the web reference name to MyService
press Add Reference
All the necessary proxy classes will be created.


A Web References folder will be created
SS



View > Other Windows > Object Browser
Expand - WebServicesProject.MyService
You will see four operations and each operation will have an EventArgs and an EventHandler


Synchronous

Add the following code to the button event handler
This will call the service synchronously and block the main thread.

private void button1_Click(object sender, EventArgs e) 
{
    WebServicesProject.MyService.Calculator service = new WebServicesProject.MyService.Calculator();
    int myresult = service.Add(20, 20);
    this.textBox1.Text = myresult.ToString();
}

Asynchronous

Add the following code to the button event handler
This will run the code asynchronously and not block the main thread.
This creates the event handler at run-time.

private void button1_Click(object sender, EventArgs e) 
{
    WebServicesProject.MyService.Calculator service = new WebServicesProject.MyService.Calculator();
    service.AddCompleted += new MyService.AddCompletedEventHandler(this.Method_Service_AddCompleted);
    service.AddAsync(20, 20);
}

private void Method_Service_AddCompleted(object sender, MyService.AddCompletedEventArgs e)
{
    this.textBox1.Text = e.Result.ToString();
}


SOAP Service with Service Reference

Added in .NET 3.5
This supports services that implement WS-I Basic Profile 1.1 (plus others)
This is a wrapper over svcutil.exe and creates a client proxy




Example

Open Visual Studio 2022 as Administrator.
New Project, Windows Forms App (.NET Framework) C#
Create folder C:\temp\winforms\


Create new project,
Press Next


Project name - WebServicesProject
Location - C:\temp\winforms
Framework - .NET Framework 4.8



An entry will appear under Connected Services
SS



Synchronous





Asynchronous



Connecting




System.Net.HttpWebResponse oResponse; 
oResponse = oHttpWebRequest.GetResponse

System.IO.StreamReader oStreamReader;
oStreamReader = new System.IO.StreamReader(oResponse.GetResponseStream, System.Text.Encoding.UTF8, true)

oStreamReader.ReadToEnd();




© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext