Introduction
Web Service is recognized as a software application that leverages XML for communication among different software systems using standard internet protocols. Essentially, Web Services facilitate interaction with remote objects over the internet.
Here are some points about the Web Service.
- Web Service is not dependent on any particular language.
- Web Service is a protocol Independent.
- Web Service is platform-independent.
- Web Service is known as the Stateless Architecture. These services are dependent only on the given input.
- Web Service is also Scalable.
- Web Service is based on the XML (Open, Text-Based Standard).
Technology Used in Web Service
XML: A Web Service solely defines the data, allowing applications that comprehend XML based on the programming language or platform to structure the XML in various formats.
SOAP: The interaction between the services and the application is facilitated by the SOAP protocol.
WSDL provides a standardized approach that is beneficial for defining Web Services to other applications.
By utilizing UDDI, users are able to explore various Web Service directories.
At the moment of implementing these technologies, developers can package applications as services and publish them on the network.
Advantages of Web Services
- Web Services always use the open, text-based standard. Web service uses all those components even they are written in various languages for different platforms.
- Web Service promotes the modular approach of the programming so that the multiple organizations can communicate with the same web service.
- Web Services are easy to implement but expensive because they use the existing infrastructure, and we can repackage most of the applications as the Web Service.
- Web Service reduces the cost of enterprise application integration and B2B communications.
- Web Services are the interoperable Organization that contains the 100 vendors and promote them interoperability.
Limitations of Web Services
Limitation of Web Services are:
- One of the limitations of the Web Services is that the SOAP, WSDL, UDDI requires the development.
- Supports to the interoperability is also the limitation of the Web Service.
- The limitation of web service is also royalty fees.
- If we want to use web services for the high-performance situation, in that case, web service will be slow.
- The use of web service increases the traffic on the network.
- The security level for Web Services is low.
- We use the standard procedure to describe the quality of particular web services.
- The standard for the Web Service is in the draft form.
- To retain the intellectual property of the specific standard by the vendor is also the limitation of the web service.
Example of the Web Service
Web Service can do almost any kind of task.
Web Portal: A web portal is employed to retrieve the latest news headlines from the associated web service.
For weather updates, we will utilize the Weather Reporting Web Service to showcase the current weather details on our website.
Stock Quotation: The most recent details regarding the stock market can be showcased on our website using the Stock Quotation feature.
By leveraging the news headline Web Service, we have the ability to display the most recent news updates on our website.
We have the ability to develop web services and provide them for public use. For instance, consider creating a Free SMS Sending Service that includes a company advertisement in the footer. This way, every time someone utilizes this service, they inadvertently promote our company. There are numerous possibilities for leveraging web services to our advantage.
To initiate the creation of a Web Service, it is essential to begin by conceptualizing a specific scenario. Understanding the purpose and necessity of Web Services is the primary step in their development.
The need for Web Service
We are considering a situation where we aim to display various details on our website such as regional, national, and international information. Developing code for these functionalities from scratch would be a time-consuming and laborious task. Fortunately, other websites already offer this information, making it possible for us to leverage their existing logic. However, a challenge emerges: how can we integrate this pre-existing logic into our own application?
The solution to this problem is Web Services .
By leveraging the Web Service, we have the ability to recycle another individual's business logic rather than duplicating it. Implementing someone else's business logic simply involves writing a small amount of code. This approach is akin to utilizing libraries, APIs, DLLs, and plug-ins.
The primary contrast between the libraries of API and the Web Service is that the Web Service is situated remotely on a separate server.
Web Services can be accessed by other applications. These services represent segments of the business logic that are stored on the web, enabling utilization by other applications.
Here we have some points about the Web Services.
Note1: Web Services are not limited only to the .Net Framework. The standards of Web Services were already defined before the release of the .NET. Web Services and supported by the vendors other than Microsoft.
Note:2: Web Services can also work on the cross-platform. If the services were written in one language, these could be used by the other application despite, and the application used the other language. If we want to use the web services, the only way for that is we only need the internet to connect where we will make the HTTP request.
As it is commonly understood, Web Services are designed to be compatible across different platforms. However, it is essential to have a common language that allows requesting services and receiving responses effectively. XML is the chosen format for Web Services due to its ease of comprehension.
This is the sole purpose behind developing web services using XML-based data exchange standards.
Web Services make use of the Set of Data type, which is readily identified by the XML Schema.
Web Services rely on basic data types such as strings and numbers to facilitate communication. Utilizing these data types is essential for interacting with Web Services. It's important to note that sending proprietary .NET objects like images, FileStreams, or EventLogs is not feasible. Other programming languages lack the capability to communicate with these specific .NET objects. Even if devices are employed to transmit them to the client, the diverse programming languages will struggle to interpret such data.
Note:3 If we want to work with the .NET objects, we can use the .NET remoting. .NET remoting is known as distributed technology through which we can use the .NET objects. But the non-.NET client can't use it.
Data Types supported by the Web Service.
- Built-in Types (Basic): Data Types used by the Web Services are: Web Services uses the built-in C# data types like short, int, long, short, float, char, byte, string, and DateTime.
- Objects: WPF uses the object of the user-defined class. In spite of this thing that the class contains the methods, the class will not be possible to transmit to the client.
- Arrays: WPF uses the arrays of any supported data type (built-in or customs). We can also use the ArrayList in WPF.
- Enumerations: WPF supports enum. For the value of the enumeration, WPF uses the string name. WPF will not use integer.
- XmlNode: Objects which are based on the System.Xml.XmlNode represents the portion of the XML document. We can use the XmlNode to send the arbitrary XML.
The WPF framework offers support for dataSet and DataTable structures, however, it does not provide support for ADO.NET data entities such as DataColumns and DataRows.
Create Web Service
A basic asmx page is commonly referred to as a Web Service. To develop this web service, we will utilize Visual Studio 2017, which operates on the .NET Framework version 4.8. The steps for creating the Web Service are outlined below:
Initially, we will develop a web application to establish the foundation for the web service.
To do that, we need to select the project by going to File -> Select Project, as indicated in the screenshot below:
The CSS code snippet below illustrates the styling for a placeholder diagram. This diagram includes a background with a gradient effect, rounded corners, padding, margin spacing, and centralized text alignment. Additionally, the diagram features an icon with a specific font size and a corresponding text section for further details.
After that, a new window will appear as depicted in the following image:
Next, you should choose Web, followed by Asp.Net Web Application, then enter the desired name for the Web Application, and finally click on the OK button.
The <style> section below shows the CSS styling for a placeholder diagram:
.placeholder-diagram { background: linear-gradient(135deg, #374151 0%, #1f2937 100%); border-radius: 12px; padding: 40px; margin: 20px 0; text-align: center; }
.placeholder-diagram .placeholder-icon { font-size: 3rem; margin-bottom: 10px; }
.placeholder-diagram .placeholder-text { color: #9ca3af; font-size: 1rem; }
This concludes the CSS styling for the placeholder diagram.
Following this action, a fresh window will appear for us, as illustrated below:
The <style> component features a CSS style with a distinctive linear gradient background and rounded corners. This design includes a generous padding, vertical margin, and centered alignment. Within this component, there is an icon element styled with a specific font size and margin for spacing. The text content within the component is styled with a color and font size to enhance readability. </style>
To establish the Web Service, we will initiate by right-clicking on the project name, then selecting Add followed by Add New Item. This process is illustrated in the screenshot below:
The CSS code snippet shown below creates a visual placeholder diagram. It includes a background with a gradient color scheme, rounded corners, padding, margin spacing, and center alignment. The diagram features an icon with a specific size and spacing, along with text in a distinct color and font size.
After this action, a new window will pop up. Navigate to Web -> Choose Web Service(.asmx page) -> Assign a name to the Web Service as depicted in the following image:
The CSS code snippet below showcases a styled placeholder diagram:
.placeholder-diagram {
background: linear-gradient(135deg, #374151 0%, #1f2937 100%);
border-radius: 12px;
padding: 40px;
margin: 20px 0;
text-align: center;
}
.placeholder-diagram .placeholder-icon {
font-size: 3rem;
margin-bottom: 10px;
}
.placeholder-diagram .placeholder-text {
color: #9ca3af;
font-size: 1rem;
}
After integrating the Web Service into the application, a new dialog will be displayed as depicted below:
The CSS code snippet below illustrates the styling for a placeholder diagram. This diagram includes a background gradient, border radius, padding, margin, and text alignment properties. The placeholder icon is defined with a specific font size and margin, while the placeholder text has a designated color and font size.
Visual Studio generates an immutable web service analysis template utilized within the Visual Studio environment.
Explanation of Default Code
[WebService(Namespace= "http://tempuri.org/") )]
The XML-based Web Service necessitated a distinct namespace for the client application, aiding in differentiating it from other services available on the Web. The Web Service currently employs the default namespace, tempura.org, which is designated for XML Web services in the developmental phase. However, XML Web Services intended for publication ought to adopt a persistent namespace. When transitioning to a production environment, Web Services instances should substitute the existing URI with a more relevant and purposeful one.
We will designate the Web Service namespace to be managed by the organization behind the Web Service. In this scenario, we will consider the organization's internet domain name, which can be integrated into the namespace. This namespace for the XML Web service will resemble URLs, which are commonly employed to reference specific resources on the Web.
Points to be noted:
Here are some considerations to keep in mind when developing a web service:
- It is important to remember that only one [WebService] tag is allowed.
- Modifying the namespace will not impact the web service namespace.
[WebServiceBinding(AdheresTo = WsiProfiles.BasicProfile1_1)]
Web services do not inherently support direct method overloading. To enable method overloading in a Web Service, the MessageName property must be included. This property serves to distinguish between two methods within the web service that share the same name and parameters.
[WebServiceBinding(ConformsTo= WsiProfiles.BasicProfile1_1)] should be changed to [WebServiceBinding(ConformsTo = WsiProfiles.None)].
[WebMethod]
public int SumOfNums(int FirstNumber, int SecondNumber)
{
return FirstNumber + SecondNumber;
}
//here we will use MessageName property to do the differentiation between both of the methods.
[WebMethod(MessageName = "SumOfFloats")]
public float SumOfNums(float FirstNumber, float SecondNumber)
{
return FirstNumber + SecondNumber;
}
If we need to invoke the Web service from the script, we will utilize ASP.NET, AJAX, and remove the comment from the line below.
[System.Web.Script.Services.ScriptService]
[WebMethod]
This specific attribute is typically positioned at the beginning of the method within the Web Service code. The [WebMethod] attribute serves the purpose of indicating that the associated method is accessible to users or clients.
If this attribute is eliminated, the client will lose visibility into the method's specifics, leading to an inability to carry out its implementation.
Proxy class or WSDL
WSDL (Web Service Development Language) document is used to generate the proxy class of the Web Service. WSDL document defines the Web Service. WSDL document contains the
- All the method which is exposed by the Web service.
- WSDL document contains the parameters and their types.
- WSDL document contains the return type of the methods.
Visual Studio leveraged the provided details to generate the proxy class. Subsequently, the client application will invoke methods within this proxy class. The proxy class is tasked with serializing the parameters, formatting the SOAP request message, and transmitting it to the Web Service. Upon execution, the Web Service will respond by sending back the SOAP return message to the Proxy. Following this, the proxy class will handle the deserialization of the SOAP response message before passing it back to the Client application. This process eliminates the necessity to convert .NET CLR objects to and from the SOAP format, as the proxy class undertakes all serialization and deserialization tasks. This streamlined approach significantly simplifies the developer's workflow.
Now we will see the WebService1.asmx.cs window:
- WebService.asmx.cs page includes the System.Web.Services, and it also consists of the four other namespaces which are included by the visual Studio in the Web Application.
- "Service1" class is inherited from the "System.Web.Services.WebServices" . After inheriting the class from the "System.Web.Services.WebService" we can access the built-in ASP.Net objects such as (Application, Session, User, Context, Server ). If there is not any need for the built-in objects of .NET, then there is also do not any need of the service class from "WebService".
- "Service1" includes the "WebService" attribute. If we want to expose any class as a service, then there is also a need to include the attribute of the "WebService".
The WebService attribute holds various characteristics such as:
The namespace attribute ensures the Service is distinctively recognized. It is a key feature of XML. Given that a client application may host various services, collisions can occur. Providers must ensure namespace uniqueness to prevent such clashes.
By utilizing the Name attribute, we can assign a clear and descriptive title to the Service.
Description: This property is used to avoid a brief description of the Service.
- "Service1" contains another attribute as well, which is "WebServiceBinding". This is used to indicate the standard of the Service. If the Service does not follow this standard, we will get an exception.
- With the Service, one more attribute is added, which is "[System.Web.Script.Services.ScriptService]", for making the Service accessible from the client script, Services should be decorated with this Service.
- The "Service1" class contains a method "Hello World". This method is decorated with the "[WebMethod]" attribute. The client application accesses the service method. The Client Application should add the "Service1" method.
There is a possibility that the Service employs certain methods for internal operations. The client application is not required to utilize these methods. It is unnecessary to invoke these methods with the Web Method attribute.
The WebMethod attribute includes the Name and Description properties, allowing us to specify a descriptive name or description accordingly.
Mark-up
Now we will see the mark-up.
To access the markup, you need to right-click on Service1.asmx within the Solution Explorer window and then choose the option to view the markup, as illustrated in the screenshot below:
The CSS code snippet below illustrates the styling of a placeholder diagram:
.placeholder-diagram { background: linear-gradient(135deg, #374151 0%, #1f2937 100%); border-radius: 12px; padding: 40px; margin: 20px 0; text-align: center; }
.placeholder-diagram .placeholder-icon { font-size: 3rem; margin-bottom: 10px; }
.placeholder-diagram .placeholder-text { color: #9ca3af; font-size: 1rem; }
Within the Service1.asmx file, it becomes apparent that the Service employs the WebService directive alongside an attribute. This indicates that the Service is called upon by the application itself rather than by the end-user. Consequently, the asmx page does not contain any markup.
Service1.asmx
<%@ WebService Language="C#" CodeBehind="Service1.asmx.cs" Class="WebApplication7.Service1" %>
Here are some points about the Service1.asmx.
- "Web Service" directive: This directive shows that the asmx page is a web service.
- "Language"="C#": This indicates that the C# language is used for the Service.
- "CodeBehind": This property has not any role with the ASP.NET or web service. CodeBehind is the property of the Visual Studio. This property is used to map the asmx page with the code behind the page.
- "Class" property contains the qualified name of the class. This is the entry point of the Service, just like the main in C language.
Now we will execute this program by clicking the F5 button. In this section, you will discover a hyperlink to the Service Description, depicted in the screenshot below:
The CSS code snippet below demonstrates the styling for a placeholder diagram:
.placeholder-diagram {
background: linear-gradient(135deg, #374151 0%, #1f2937 100%);
border-radius: 12px;
padding: 40px;
margin: 20px 0;
text-align: center;
}
.placeholder-diagram .placeholder-icon {
font-size: 3rem;
margin-bottom: 10px;
}
.placeholder-diagram .placeholder-text {
color: #9ca3af;
font-size: 1rem;
}
Upon selecting the Service Description link, users will be directed to the Service's WSDL document, as illustrated in the screenshot below:
The <style> component includes a CSS class called placeholder-diagram. This class features a background with a linear gradient, border radius of 12 pixels, padding of 40 pixels, a margin of 20 pixels on the top and bottom, and text alignment set to center. Within the placeholder-diagram class, there are two nested classes: placeholder-icon with a font size of 3 rem and a margin-bottom of 10 pixels, and placeholder-text with a color of #9ca3af and a font size of 1 rem. </style>
There is an additional hyperlink leading to the HelloWorld. Upon selecting this link, it will navigate us to the testing page.
The <style> class defines the styling for a diagram placeholder. Within this class, the background is set using a linear gradient with specific color values. It also includes properties for border radius, padding, margin, and text alignment. The placeholder-icon within this class has a font size of 3rem and a margin-bottom of 10px. Additionally, the placeholder-text has a color of #9ca3af and a font size of 1rem. This styling is essential for creating visually appealing placeholders in web development.
Upon selecting the link, we will be redirected to the testing page of Service1 Web Service.
The <style> snippet displays a placeholder diagram with a stylish design. The diagram is enclosed in a container with a rounded border and a gradient background. It includes an icon and text, both centered within the container. The icon is large and positioned above the text, creating a visually appealing layout.
Implementation of web Service
Now, we are going to carry out the implementation of the Service. Subsequently, we will update the filename "Service1" within the Solution Explorer to "MyService". Here, the adjustment involves renaming the class name from Service1 to MyService. Following this, it is time to access the mark-up (.asmx) page.
The styling for placeholders is defined in the following CSS code snippet:
.placeholder-diagram { background: linear-gradient(135deg, #374151 0%, #1f2937 100%); border-radius: 12px; padding: 40px; margin: 20px 0; text-align: center; }
.placeholder-diagram .placeholder-icon { font-size: 3rem; margin-bottom: 10px; }
.placeholder-diagram .placeholder-text { color: #9ca3af; font-size: 1rem; }
From the provided image, it is evident that Visual Studio is encountering a resolution issue with the "Service1" in the class property. In this context, the class displays the complete name of the Service, which was altered from Service1 to MyService; however, Visual Studio is unable to recognize this modification.
Here we modify the attribute of the class to "Web application.MyService" and update the "CodeBehind" attribute from "Service1.asmx.cs" to "MyService.asmx.cs" to match the new file name.
MyService.asmx
<%@ WebService Language="C#" CodeBehind="MyService.asmx.cs" Class="WebApplication7.MyService" %>
MyService.asmx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Serialization;
namespace WebApplication7
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class MyService : System.Web.Services.WebService
{
[WebMethod]
public int SumOfNums(int First, int Second)
{
return First + Second;
}
}
}
Following this step, the Service is now prepared for utilization. Subsequently, we will proceed with compiling and executing this application.
Upon compilation, a new window will launch, as demonstrated in the screenshot below:
The <style> element includes a CSS class for a diagram with a specific background gradient, border radius, padding, margin, and center alignment. This diagram also contains a CSS class for the icon within the diagram and another class for the text color and font size. The styling is designed to enhance the visual representation of information on a webpage.
Testing of a Web Service
Now, to execute the application, simply click on the F5 key. Upon doing so, the http://localhost:62639/MyService.asmx will automatically load. Within this page, you will find a hyperlink leading to the Service Description (which includes the WSDL document and Web Service documentation) and another link for SumOfNums. This particular page serves as a testing ground for the SumOfNums function, as illustrated in the screenshot below:
The CSS code snippet below demonstrates a placeholder design with a dark background color, rounded corners, padding, and center-aligned text. The placeholder includes an icon with a size of 3rem and text with a font size of 1rem.
Now we are going to implement the OOP (Object-Oriented Programming) principle of method overloading. Next, we will introduce the WebMethod within the MyService class.
MyService.asmx.cs
using System;
using System.Collections.Generic;
using System. Linq;
using System. Web;
using System.Web.Services;
using System.Web.Script.Serialization;
namespace WebApplication7
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class MyService : System.Web.Services.WebService
{
[WebMethod(MessageName = "SumOfFloats")]
public float SumOfNums(float First, float Second)
{
return First + Second;
}
}
}
Now, to launch this program, simply click on the F5 key. The http://localhost:62639/MyService.asmx will then appear, providing access to the Service Description (the WSDL document and web service documentation). Within this page, you will find a link named SumOfNums, which serves as the test page for the SumOfNums function, illustrated in the screenshot below:
The CSS code snippet below illustrates the styling for a placeholder diagram:
.placeholder-diagram { background: linear-gradient(135deg, #374151 0%, #1f2937 100%); border-radius: 12px; padding: 40px; margin: 20px 0; text-align: center; }
.placeholder-diagram .placeholder-icon { font-size: 3rem; margin-bottom: 10px; }
.placeholder-diagram .placeholder-text { color: #9ca3af; font-size: 1rem; }
After inputting data into the initial textbox and the subsequent textbox, the method displayed in the following image will be triggered:
The CSS code snippet below defines the styling for a placeholder diagram. It includes a linear gradient background, border radius, padding, margin, and text alignment properties. The placeholder icon within the diagram is styled with a specific font size and margin bottom. The text content inside the diagram is styled with a particular color and font size.
Method Overloading
Now, we are going to implement the overloading technique in the Service. Note that web services do not allow method overloading, so attempting to do so will result in an error. Let's demonstrate an example to illustrate how method overloading is attempted in a web service and the error that occurs due to lack of support for overloading.
MyService.asmx.cs
using System;
using System.Collections.Generic;
using System. Linq;
using System. Web;
using System.Web.Services;
using System.Web.Script.Serialization;
namespace WebApplication7
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class MyService : System.Web.Services.WebService
{
[WebMethod]
public int SumOfNums(int First, int Second)
{
return First + Second;
}
[WebMethod(MessageName = "SumOfFloats")]
public float SumOfNums(float First, float Second)
{
return First + Second;
}
}
}
OUTPUT
The CSS code below demonstrates the styling for a placeholder diagram:
.placeholder-diagram { background: linear-gradient(135deg, #374151 0%, #1f2937 100%); border-radius: 12px; padding: 40px; margin: 20px 0; text-align: center; }
.placeholder-diagram .placeholder-icon { font-size: 3rem; margin-bottom: 10px; }
.placeholder-diagram .placeholder-text { color: #9ca3af; font-size: 1rem; }
In the previous scenario, the Web Service lacks support for method overloading, resulting in an error indicating that the Service "WebApplication7.MyService" does not adhere to WS-I Basic Profile v1.1. To enable method overloading, we need to take the following actions: either eliminate the "[ WebServiceBinding (ConformsTo = WsiProfiles .BasicProfile1_1)]," or introduce modifications like "[WebServiceBinding(ConformsTo = WsiProfiles.None)]".
To enable method overloading, adjustments need to be made in the code, as demonstrated in the highlighted box below:
using System;
using System.Collections.Generic;
using System. Linq;
using System. Web;
using System.Web.Services;
using System.Web.Script.Serialization;
namespace WebApplication7
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
//make the WsiProfiles to None
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class MyService : System.Web.Services.WebService
{
[WebMethod]
public int SumOfNums(int First, int Second)
{
return First + Second;
}
//here we have to add the MessageName property to make the difference between both of the methods.
[WebMethod(MessageName = "SumOfFloats")]
public float SumOfNums(float First, float Second)
{
return First + Second;
}
}
}
After implementing these modifications, the Web Service will appear similar to what is displayed in the screenshot below:
The <style> CSS class defines a placeholder diagram with a linear gradient background color, rounded corners, padding, margin, and centered text alignment. It includes a placeholder icon with a size of 3rem and some placeholder text in a color of #9ca3af and a font size of 1rem. </style>
Here, the web service accommodates a method with an identical title. Introducing the message name attribute allows us to distinguish between the two methods effectively.
By leveraging the aforementioned characteristic, we are able to implement method overloading within the Web Service.
Testing of the Page
After selecting the SumOfFloats option, the webpage will be directed to the http://localhost:62639/MyService.asmx?op=SumOfFloats where we will observe that the "?op=SumOfNums" is added to the Service URL. This specific page features a pair of text boxes for the dual input values (First, Second), with the SumOfNums value serving as an input parameter and an "invoke" button. Upon activating this invoke button, the navigation will lead to the http://localhost:62639/MyService.asmx/SumOfFloats, page that displays the result of the SumOfNums method in XML format.
The placeholder diagram features a CSS style with a background gradient, border radius, padding, margin, and text alignment. Within the diagram, there is an icon with a specific font size and margin, as well as text with a defined color and font size.
After selecting the invoke button, we will be directed to the http://localhost:62639/MyService.asmx/SumOfFloats page where the information is presented in XML format.
The <style> code snippet displays a diagram with a custom background color, border radius, padding, margin, and text alignment. The diagram includes an icon and accompanying text. The background color is a linear gradient from #374151 to #1f2937, with a border radius of 12 pixels, 40 pixels of padding, and a vertical margin of 20 pixels. The text inside the diagram is centered, with the icon having a font size of 3rem and a 10-pixel margin at the bottom. The text color is #9ca3af, with a font size of 1rem.
Similarly, upon selecting the "SumOfNums MessageName="SumOfFloats"" option, we will be directed to the "http://localhost:62639/MyService.asmx?op=SumOfFloats" page. This allows the client application to access the "SumOfNums MessageName="SumOfFloat"" function, also referred to as "SumOfFloats".
Here arises a query about the origin of the test page. Despite not incorporating the Mark-up, the page was still displayed.
Test Pages do not form a component of the Web Service. The Test Page is generated by ASP.NET through the utilization of the Web Page located at c:\[WinDir]\Microsoft.NET\Framework\[Version]\Config\DefaultWsdlHelpGenerator.aspx. The Test Page is influenced by the "Reflection" concept.
WSDL Document
Web Services are inherently self-descriptive, indicating that ASP.Net autonomously supplies all the necessary details for clients to utilize a web service through the WSDL document. The WSDL document informs clients about the available methods within the Web Service, including the parameters and return values utilized by each method, and outlines how a client application can interact with them. WSDL adheres to the XML standard.
Hosting of the Web Service
For the deployment of the web service, we will establish the connection to the Service and integrate it into various applications. Assuming the port number may vary, our next step involves deploying the Service on the Internet Information Services (IIS) to determine the specific server address. To achieve this, we will navigate to Internet Information Services -> Access the default web site -> Right-click on the application -> Incorporate the Application -> locate the physical location of our Service for the physical path field -> Select "OK". Subsequently, we will test the application using the designated alias http://localhost/WebServiceDemo/ to ensure successful hosting. During this process, we may encounter an "HTTP Error 403.14-Forbidden" due to the absence of a default document for the application. To rectify this issue, we will designate a page as the default document, such as "MyService.asmx". After this adjustment, the application can be accessed by entering the following URL in the browser: localhost/WebServiceDemo/MyService.asmx.
Consume the Web Service from the Client Script
We have the flexibility to integrate a web service into any kind of application. In this case, we are going to develop a .Net web application. To achieve this, we will adhere to the steps outlined below:
Right-click on the Solution Explorer, then select Add followed by New Project as depicted in the screenshot below:
The styling for the placeholder diagram includes a background with a linear gradient, border radius of 12px, padding of 40px, margin of 20px at the top and bottom, and center alignment. Inside the diagram, there is an icon with a font size of 3rem and a margin bottom of 10px, along with text in a color of #9ca3af and a font size of 1rem.
After selecting the "New Project" option, a new window will appear, similar to the image displayed below:
The <style> CSS class defines the styling for a placeholder diagram, including background gradient, border radius, padding, margin, and text alignment. Within the placeholder diagram, the .placeholder-icon class controls the size and margin of the icon, while the .placeholder-text class determines the color and font size of the text content. </style>
Next, to interact with the web service, it is necessary to generate a proxy class. The process of creating this proxy class involves the following steps:
Proxy Class
To generate the proxy class, you need to right-click on References, then choose Add Service Reference, following the instructions illustrated in the screenshot below:
The given code snippet showcases a placeholder diagram designed with a stylish background, border radius, padding, margin, and center-aligned text. The diagram includes an icon with a font size of 3rem and a slight margin at the bottom. The text within the diagram is presented in a color of #9ca3af and a font size of 1rem.
Upon selecting the Add Service Reference option, a new window will be displayed, as depicted in the following image:
The style of the placeholder diagram includes a background with a gradient effect, rounded corners, padding, margin spacing, and center alignment. Additionally, it features an icon with a specific size and a text section with a designated color and font size.
Explanation of the above window:
In this section, we'll input the URL of the web service we've developed and proceed by clicking the Go button.
Upon selecting the Go button, the system will initiate a search for the specified address.
Within the namespace, you can specify the Service name and proceed by selecting the OK button. This action will incorporate the reference to the web service into the project.
Now, we are going to include the Web Form in our application. To do this, we will proceed with the steps outlined below:
- Begin by right-clicking on the project within the solution explorer-> opt for add->then select web form as demonstrated in the screenshot provided below:
The CSS code snippet below demonstrates the styling for a placeholder diagram:
.placeholder-diagram { background: linear-gradient(135deg, #374151 0%, #1f2937 100%); border-radius: 12px; padding: 40px; margin: 20px 0; text-align: center; }
.placeholder-diagram .placeholder-icon { font-size: 3rem; margin-bottom: 10px; }
.placeholder-diagram .placeholder-text { color: #9ca3af; font-size: 1rem; }
After selecting the Web Form option, a new window will open prompting the user to enter the name of the web form, as illustrated in the screenshot below:
The CSS code snippet below illustrates a placeholder diagram styled with a background gradient, border radius, padding, margin, and text alignment for a visually appealing representation. The placeholder includes an icon with a size of 3rem and text styled in a color of #9ca3af and a font size of 1rem.
Here in the preceding screenshot, we specified the title of the web form and subsequently selected the OK button.
Within the Web Form, a table will be generated to implement the pre-existing procedure utilizing the Web Service.
In the WebForm1.aspx file, the following code snippet illustrates the actions we have taken:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CalculatorWebApplication.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<table style="font-family:Arial">
<tr>
<td>
<b>First Number</b>
</td>
<td>
<asp:TextBox ID="txtFirstNumber" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<b>Second Number</b>
</td>
<td>
<asp:TextBox ID="txtSecondNumber" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<b>Result</b>
</td>
<td>
<asp:Label ID="lblResult" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnadd" runat="server" Text="Add" OnClick="btnadd_Click" />
</td>
</tr>
</table>
</form>
</body>
</html>
In the provided code, set up a table to incorporate two input fields, namely textbox1 for inputting the initial number and textbox2 for inputting the subsequent number. Implement a button that will facilitate the addition of these two numbers.
The visual representation of the aforementioned code can be observed in the following image:
The <style> section showcases a placeholder diagram designed with a stylish background using a linear gradient of colors and a rounded border for a modern look. The diagram is structured with generous padding and centered alignment for a visually appealing display. Within the diagram, an icon is included with a substantial font size and adequate spacing from the text below. The text in the diagram is presented in a color that complements the background, maintaining a cohesive design.
Here, two input fields are provided for users to enter the first number and second number. The addition operation is performed by clicking the add button to calculate the sum of the values entered in both textboxes.
Following a double-click on the Add button, the transition to the coding page will occur, redirecting us to the WebForm.aspx.cs page.
To implement the Web Service method, the following code will be executed upon clicking the button.
WebForm.aspx.cs
using System;
using System.Collections.Generic;
using System. Linq;
using System. Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CalculatorWebApplication
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnadd_Click(object sender, EventArgs e)
{
CalculatorService.CalculatorWebServiceSoapClient client = new CalculatorService.CalculatorWebServiceSoapClient();
int result= client.Add(Convert.ToInt32(txtFirstNumber.Text),
Convert.ToInt32(txtSecondNumber.Text));
lblResult.Text = result.ToString();
}
}
}
Now, let's initiate the web service by pressing the F5 key. The result will be displayed as depicted in the following image:
OutPut
The <style> element defines the styling for a diagram placeholder, including background, border radius, padding, margin, and text alignment. Within the placeholder, there is an icon with a specific size and margin, as well as text with a defined color and font size. </style>
Wrap Up
Here we are leveraging the advantages of a web service within this software. No custom logic was implemented for performing the sum of two numerical values. In our online calculator tool, the addition operation is solely handled by the web service method without the need for additional logic. The provided image illustrates the result of adding two numbers, specifically 23.