<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>create soap service asp &#8211; ASP.NET Hosting Reviews and Guides</title>
	<atom:link href="https://topreviewhostingasp.net/tag/create-soap-service-asp/feed/" rel="self" type="application/rss+xml" />
	<link>https://topreviewhostingasp.net</link>
	<description>ASP.NET Hosting &#124; Reviews &#124; Tips &#38; Tutorial</description>
	<lastBuildDate>Tue, 27 Jun 2023 09:23:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://topreviewhostingasp.net/wp-content/uploads/2017/01/cropped-trhaico-32x32.png</url>
	<title>create soap service asp &#8211; ASP.NET Hosting Reviews and Guides</title>
	<link>https://topreviewhostingasp.net</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to Create SOAP Web Service ASP.NET Core</title>
		<link>https://topreviewhostingasp.net/how-to-create-soap-web-service-asp-net-core/</link>
					<comments>https://topreviewhostingasp.net/how-to-create-soap-web-service-asp-net-core/#respond</comments>
		
		<dc:creator><![CDATA[Jacques Hunt]]></dc:creator>
		<pubDate>Tue, 27 Jun 2023 08:26:06 +0000</pubDate>
				<category><![CDATA[Hosting Tips]]></category>
		<category><![CDATA[asp net core]]></category>
		<category><![CDATA[asp net core tips]]></category>
		<category><![CDATA[asp net core tutorial]]></category>
		<category><![CDATA[create soap service asp]]></category>
		<category><![CDATA[soap service asp net]]></category>
		<guid isPermaLink="false">https://topreviewhostingasp.net/?p=3594</guid>

					<description><![CDATA[We will learn how to construct and use Soap Web Services in Dotnet Core in this tutorial. In software development, Web services implementation comes in two flavors: SOAP and REST API. Web Services are programs that enable internet-based device-to-device communication. Please make sure you have installed The latest version of Visual Studio SQL Server Steps to [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>We will learn how to construct and use Soap Web Services in Dotnet Core in this tutorial. In software development, Web services implementation comes in two flavors: SOAP and REST API. Web Services are programs that enable internet-based device-to-device communication.</p>
<p>Please make sure you have installed</p>
<ul>
<li>The latest version of <a href="https://visualstudio.microsoft.com/downloads/">Visual Studio</a></li>
<li>SQL Server</li>
</ul>
<h2>Steps to Create SOAP Demo Application</h2>
<h3 class="wp-block-heading">1. Create a SOAP Webservice in Visual Studio 2019</h3>
<p>1. Create an empty ASP.NET Web Application(.NET Framework) .We will use this project as the soap service demo .To do that just follow the steps below.</p>
<ul>
<li>Select <strong>File</strong> &gt; <strong>New</strong> &gt; <strong>Project</strong>.</li>
<li>Select <strong>ASP.NET Web</strong> <strong>Application</strong>(.NET Framework). Name the project <strong>SoapDemo </strong>to have the same namespace as my project. Click <strong>Create</strong>.</li>
<li>Select an Empty <strong>ASP.NET Web Application</strong>(.NET Framework).</li>
<li>Lastly, Click on <strong>Create</strong>.</li>
</ul>
<p><img fetchpriority="high" decoding="async" class="size-full wp-image-3595 aligncenter" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/visual-studio.jpg" alt="" width="1016" height="684" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/visual-studio.jpg 1016w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/visual-studio-300x202.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/visual-studio-768x517.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/visual-studio-50x34.jpg 50w" sizes="(max-width: 1016px) 100vw, 1016px" /></p>
<p><img decoding="async" class="size-full wp-image-3596 aligncenter" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/visual-studio-2.jpg" alt="" width="1016" height="684" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/visual-studio-2.jpg 1016w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/visual-studio-2-300x202.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/visual-studio-2-768x517.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/visual-studio-2-50x34.jpg 50w" sizes="(max-width: 1016px) 100vw, 1016px" /></p>
<p>This is what your solution with an empty template would look like after creating a new project. See the picture below.</p>
<p><img decoding="async" class="size-full wp-image-3597 aligncenter" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/visual-studio-3.jpg" alt="" width="932" height="637" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/visual-studio-3.jpg 932w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/visual-studio-3-300x205.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/visual-studio-3-768x525.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/visual-studio-3-50x34.jpg 50w" sizes="(max-width: 932px) 100vw, 932px" /></p>
<p>2. Add a new item by right-clicking your project solution and select Add » NewItem. Then search for Web Service ASMX.</p>
<div id="ads-slot1"><img loading="lazy" decoding="async" class="size-full wp-image-3598 aligncenter" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/asmx.jpg" alt="" width="939" height="654" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/asmx.jpg 939w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/asmx-300x209.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/asmx-768x535.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/asmx-50x35.jpg 50w" sizes="(max-width: 939px) 100vw, 939px" /></div>
<div>
<p>3. Click the &#8220;Add&#8221; button to create a template for an ASMX web service that includes the standard web method HelloWorld. View the image that is included below.</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-3599 aligncenter" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/soap-demo.jpg" alt="" width="931" height="636" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/soap-demo.jpg 931w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/soap-demo-300x205.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/soap-demo-768x525.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/soap-demo-50x34.jpg 50w" sizes="(max-width: 931px) 100vw, 931px" /></p>
<p>We are now prepared to add our sample method, which in my instance will be a login Web Method, as we now have our Soap Web service. This method will check my website&#8217;s login credentials and provide an error if they are invalid or don&#8217;t exist in my user database.</p>
<h3>2. Create a Sample WEB Method Login</h3>
<p>To use later in our ASP.Net Core Web Application, let&#8217;s construct a sample Login function. To add the sample code, adhere to the steps below.</p>
<p>1. Create a <strong>ResponseModel</strong>. This will serve as our response model template.</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-3600 aligncenter" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/Model.jpg" alt="" width="935" height="638" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/Model.jpg 935w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/Model-300x205.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/Model-768x524.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/Model-50x34.jpg 50w" sizes="(max-width: 935px) 100vw, 935px" /></p>
<p>My ResponseModel class has had the following code added. Copy the code snippet below into a new class file with the name ResponseModel.</p>
<h4 class="wp-block-heading">ResponseModel :</h4>
</div>


<pre class="wp-block-code"><code>using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 namespace SoapDemo.Models
 {
         public class ResponseModel
         {
             public T Data { get; set; }
             public int resultCode { get; set; }
             public string message { get; set; }
         }
 }</code></pre>



<p>2. Next, open the SoapDemo.asmx file and insert the example login validation method that is provided below. With this approach, the User table will be searched for the email and password. This method will return the response code, which is described as follows, once the user has been located in the database.</p>



<figure class="wp-block-table"><table><thead><tr><th>Response Code</th><th>Description</th></tr></thead><tbody><tr><td>200</td><td>Email and password found</td></tr><tr><td>500</td><td>Email and password does not exist</td></tr></tbody></table></figure>



<p>You can choose any response you want to use, but for this example I&#8217;m going to use the response code from above. I utilized the database from my earlier tutorial for this example. To construct your own ASP.NET Core login application, click the link below.</p>



<p>You can copy the code snippet below on your SoapDemo.asmx file.</p>



<pre class="wp-block-code"><code>     &#91;WebMethod]
         public  ResponseModel&lt;string&gt; login(string email, string password)
         {
             ResponseModel&lt;string&gt; response = new ResponseModel&lt;string&gt;();
  
             if (email != null)
             {
                 using (SqlConnection conn = new SqlConnection(@"Server=CODERSIGN\SQLEXPRESS01;Database=IdentityDemo;User Id=freecode;Password=freespot;"))
                 {
                     SqlCommand cmd = new SqlCommand("sp_loginUser",conn);
                     cmd.CommandType = CommandType.StoredProcedure;
                     cmd.Parameters.Add("@email", SqlDbType.NVarChar, 50).Value = email;
                     cmd.Parameters.Add("@password", SqlDbType.NVarChar, 50).Value = password;
                     
  
                     SqlDataAdapter da = new SqlDataAdapter(cmd);
                     DataTable dt = new DataTable();
                     da.Fill(dt);
  
  
                     if (dt.Rows.Count &gt; 0)
                     {
                         response.Data = JsonConvert.SerializeObject(dt);
                         response.resultCode = 200;
                     }
                     else
                     {
                         response.message = "User Not Found!";
                         response.resultCode = 500;
                     }
  
  
                 }
             }
             return response;
         } </code></pre>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="931" height="636" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/soap-demo-1.jpg" alt="" class="wp-image-3601" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/soap-demo-1.jpg 931w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/soap-demo-1-300x205.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/soap-demo-1-768x525.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/soap-demo-1-50x34.jpg 50w" sizes="(max-width: 931px) 100vw, 931px" /></figure>



<p>3. Now, run your project and make sure you see the method you just created. See the image below.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="935" height="638" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/Soap-service.jpg" alt="" class="wp-image-3602" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/Soap-service.jpg 935w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/Soap-service-300x205.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/Soap-service-768x524.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/Soap-service-50x34.jpg 50w" sizes="(max-width: 935px) 100vw, 935px" /></figure>



<figure class="wp-block-table"><table><thead><tr><th>WebMethod</th><th>Description</th></tr></thead><tbody><tr><td>HelloWorld</td><td>Default method created that will return a “Hello World” string</td></tr><tr><td>login</td><td>login validation method</td></tr></tbody></table></figure>



<p>Soap Service URL: https://localhost:44399/SoapDemo.asmx</p>



<h3 class="wp-block-heading">3. Create a Sample ASP.NET Core Web Application Project.</h3>



<p>This is a sample login application that uses cookie authentication</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="583" height="181" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/clone-login-demo.jpg" alt="" class="wp-image-3603" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/clone-login-demo.jpg 583w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/clone-login-demo-300x93.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/clone-login-demo-50x16.jpg 50w" sizes="(max-width: 583px) 100vw, 583px" /></figure></div>


<p>After that open the project using the latest Visual Studio and rebuild the solution.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="935" height="638" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/IdentityDemo.jpg" alt="" class="wp-image-3604" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/IdentityDemo.jpg 935w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/IdentityDemo-300x205.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/IdentityDemo-768x524.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/IdentityDemo-50x34.jpg 50w" sizes="(max-width: 935px) 100vw, 935px" /></figure></div>


<h3 class="wp-block-heading">4. Add a soap service reference for the ASP.NET Core application&#8217;s SoapDemo service.</h3>



<p>Now, we are ready to consume the soap service that we created above. Run your soap service and follow the steps below.</p>



<p>1. Run your soap service, this will open the browser with the soap service URL. In my case my soap URL is https://localhost:44399/SoapDemo.asmx.</p>



<p>2. Now, navigate to&nbsp;<strong>IdentityDemo&nbsp;</strong>project solution. Then right click on the&nbsp;<strong>Connected Services</strong>&nbsp;then&nbsp;<strong>Add Connected Service</strong>.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="985" height="633" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/add-services.jpg" alt="" class="wp-image-3605" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/add-services.jpg 985w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/add-services-300x193.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/add-services-768x494.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/add-services-50x32.jpg 50w" sizes="(max-width: 985px) 100vw, 985px" /></figure>



<p>3. Select&nbsp;<strong>Microsoft WCF Web Service Reference Provider</strong>&nbsp;from&nbsp;<strong>Other Services</strong>&nbsp;option. Then Input your URL and assign the service name.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="985" height="635" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/input-url.jpg" alt="" class="wp-image-3606" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/input-url.jpg 985w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/input-url-300x193.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/input-url-768x495.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/input-url-50x32.jpg 50w" sizes="(max-width: 985px) 100vw, 985px" /></figure>



<p>4. Then click Finish. This will generate references for your Soap Service.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="985" height="635" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/success-added.jpg" alt="" class="wp-image-3607" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/success-added.jpg 985w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/success-added-300x193.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/success-added-768x495.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/success-added-50x32.jpg 50w" sizes="(max-width: 985px) 100vw, 985px" /></figure>



<p>At this point, we have successfully generated the reference for our Web service project.</p>



<h3 class="wp-block-heading">5. Consume Soap Service on ASP.NET Core Application</h3>



<p>Let&#8217;s include the Service&#8217;s implementation in our project. We will add the interface and implementation to the existing IRepository and Repository classes as the ASP.NET core is an existing project.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="935" height="638" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/Irepository.jpg" alt="" class="wp-image-3608" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/Irepository.jpg 935w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/Irepository-300x205.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/Irepository-768x524.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/Irepository-50x34.jpg 50w" sizes="(max-width: 935px) 100vw, 935px" /></figure></div>


<p>This is a summary of how to obtain an instance of the soap service that we recently implemented.</p>



<p>Before you begin the following actions. The following NuGet packages need be installed.</p>



<ul><li>System.ServiceModel.Http</li><li>System.ServiceModel.Premitives</li></ul>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="854" height="488" src="https://topreviewhostingasp.net/wp-content/uploads/2023/06/success-added-2.jpg" alt="" class="wp-image-3609" srcset="https://topreviewhostingasp.net/wp-content/uploads/2023/06/success-added-2.jpg 854w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/success-added-2-300x171.jpg 300w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/success-added-2-768x439.jpg 768w, https://topreviewhostingasp.net/wp-content/uploads/2023/06/success-added-2-50x29.jpg 50w" sizes="(max-width: 854px) 100vw, 854px" /></figure>



<p>1. From IRepository class we added a&nbsp;<strong>GetInstanceAsync&nbsp;</strong>method. This method will instatiate the soap service.</p>



<pre class="wp-block-code"><code>Task&lt;SoapDemoClient&gt; GetInstanceAsync();
</code></pre>



<p>2. Then on the implementation class which is Repository.cs. I added this code.</p>



<pre class="wp-block-preformatted">public readonly string serviceUrl = "https://localhost:44399/SoapDemo.asmx";
public readonly EndpointAddress endpointAddress;
public readonly BasicHttpBinding basicHttpBinding;</pre>



<p>Repository Contructor:</p>



<pre class="wp-block-preformatted"> public Repository(IConfiguration configuration)
         {
             _configuration = configuration;
  
             endpointAddress = new EndpointAddress(serviceUrl);
  
             basicHttpBinding = new BasicHttpBinding(endpointAddress.Uri.Scheme.ToLower() == "http" ?
                             BasicHttpSecurityMode.None : BasicHttpSecurityMode.Transport);
             basicHttpBinding.OpenTimeout = TimeSpan.MaxValue;
             basicHttpBinding.CloseTimeout = TimeSpan.MaxValue;
             basicHttpBinding.ReceiveTimeout = TimeSpan.MaxValue;
             basicHttpBinding.SendTimeout = TimeSpan.MaxValue;
         } </pre>



<p><strong>GetInstanceAsync&nbsp;</strong>implementation:</p>



<pre class="wp-block-code"><code> public async Task&lt;SoapDemoSoapClient&gt; GetInstanceAsync()
    {
         return await Task.Run(() =&gt; new SoapDemoSoapClient(basicHttpBinding, endpointAddress));
    } </code></pre>



<p>3. To use this instance you can call it using the code snippet below.</p>



<pre class="wp-block-code"><code> var client = await GetInstanceAsync();
 var result = await client.loginAsync(loginView.Email, loginView.Password); </code></pre>



<p><strong>LoginAsync&nbsp;</strong>is the Login method from the&nbsp;<strong>SoapDemo&nbsp;</strong>service that we added on the Connected Service.</p>



<p>This is now the new code in my&nbsp;<strong>LoginAsync&nbsp;</strong>method.</p>



<pre class="wp-block-code"><code>  public async Task&lt;Response&lt;IdentityModel&gt;&gt; LoginAsync(LoginViewModel loginView)
         {
             Response&lt;IdentityModel&gt; response = new Response&lt;IdentityModel&gt;();
             IdentityModel userModel = new IdentityModel();
  
             try
             {
                 var client = await GetInstanceAsync();
                 var result = await client.loginAsync(loginView.Email, loginView.Password);
  
                 DataTable dt = new DataTable();
                 dt = JsonConvert.DeserializeObject&lt;DataTable&gt;(result.Body.loginResult.Data);
  
                 IdentityModel user = new IdentityModel();
                 user.ID = int.Parse(dt.Rows&#91;0]&#91;"ID"].ToString());
                 user.Email = dt.Rows&#91;0]&#91;"Email"].ToString();
                 user.Role = dt.Rows&#91;0]&#91;"Role"].ToString();
                 user.Reg_Date = dt.Rows&#91;0]&#91;"Reg_Date"].ToString();
  
                 response.Data = user;
                 response.message = (result.Body.loginResult.resultCode == 500) ? "Login failed.Please check Username and / or password" : "data found";
                 response.code = result.Body.loginResult.resultCode;
             }
             catch (Exception ex)
             {
                 response.code = 500;
                 response.message = ex.Message;
             } 
  
             return response;
         } </code></pre>



<h3 class="wp-block-heading">3. Run and Test</h3>



<p>Run the IdentityDemo and SoapDemo projects simultaneously. To create a user for you to log in, utilize the register option. Check out my earlier tutorial to get acquainted with the source code utilized here.</p>



<h2 class="wp-block-heading">Summary</h2>



<p>This lesson taught us how to use Dotnet Core to construct and use Soap Web Services. The ASP.NET core project differs from the ASP.NET MVC project in how a soap service is implemented. We can also see that using Visual Studio 2019 to create a Soap Webservice does not come with a project template for an ASMX project; instead, a new component had to be added manually. I sincerely hope that this tutorial will be useful to you and be incorporated into your future projects.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://topreviewhostingasp.net/how-to-create-soap-web-service-asp-net-core/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
