locked
How to call the function existing in the Web Service RRS feed

  • Question

  • User-786564416 posted

    I have a web service.

    I added it to my web application.

    I created a web form. I want to call the function existing after I got the References.cs

    The function is:

    System.Data.DataTable GetBenefitMonthlyList(string ListMonth, int ListType)

    The full References.cs file is:

    //------------------------------------------------------------------------------
    // <auto-generated>
    //     This code was generated by a tool.
    //     Runtime Version:4.0.30319.42000
    //
    //     Changes to this file may cause incorrect behavior and will be lost if
    //     the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------
    
    namespace WebServiceConsumer.ServiceReference1 {
        using System.Data;
        
        
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
        [System.ServiceModel.ServiceContractAttribute(ConfigurationName="ServiceReference1.MonthlyBenefitListSoap")]
        public interface MonthlyBenefitListSoap {
            
            [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/GetBenefitMonthlyList", ReplyAction="*")]
            [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
            System.Data.DataTable GetBenefitMonthlyList(string ListMonth, int ListType);
        }
        
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
        public interface MonthlyBenefitListSoapChannel : WebServiceConsumer.ServiceReference1.MonthlyBenefitListSoap, System.ServiceModel.IClientChannel {
        }
        
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
        public partial class MonthlyBenefitListSoapClient : System.ServiceModel.ClientBase<WebServiceConsumer.ServiceReference1.MonthlyBenefitListSoap>, WebServiceConsumer.ServiceReference1.MonthlyBenefitListSoap {
            
            public MonthlyBenefitListSoapClient() {
            }
            
            public MonthlyBenefitListSoapClient(string endpointConfigurationName) : 
                    base(endpointConfigurationName) {
            }
            
            public MonthlyBenefitListSoapClient(string endpointConfigurationName, string remoteAddress) : 
                    base(endpointConfigurationName, remoteAddress) {
            }
            
            public MonthlyBenefitListSoapClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                    base(endpointConfigurationName, remoteAddress) {
            }
            
            public MonthlyBenefitListSoapClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                    base(binding, remoteAddress) {
            }
            
            public System.Data.DataTable GetBenefitMonthlyList(string ListMonth, int ListType) {
                return base.Channel.GetBenefitMonthlyList(ListMonth, ListType);
            }
        }
    }
    

    Now, I want to call the function GetBenefitMonthlyList from the web form CallingForm1.aspx.cs, which as far has the code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using WebServiceConsumer.ServiceReference1;
    
    namespace WebServiceConsumer.CallingForms
    {
        public partial class CallingForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                DataTable MyDt = new DataTable();
                
            }
        }
    }

    I don't know how to call the function as I am new to C# and Web Service. In VB.net with ordinary, I use to do it as follow, so the MyDt table will retrieve all the records.

    dim MyDt as datatable = MonthlyBenefitListSoap.GetBenefitMonthlyList("052015", 3)

    But here, How can I call this function when the Page_Load?

    Wednesday, July 24, 2019 8:58 PM

All replies

  • User1120430333 posted

    I suggest that you do the tutorial, which will show how to build a Web service and then call a Web service method from a client program using VB.NET, which should help you understand what you have to do to make the call to the Web service method in the ASP.NET Web form's Page_Load event using VB.NRT

    https://www.winsocketdotnetworkprogramming.com/xmlwebservicesaspnetworkprogramming11c.html

    Thursday, July 25, 2019 7:38 AM
  • User288213138 posted

    Hi alihusain_77,

    You should instantiate the MonthlyBenefitListSoap first, and then call GetBenefitMonthlyList () method with the instantiation object.

    The code:

    ServiceReference1.MonthlyBenefitListSoap client = new MonthlyBenefitListSoap ();
    
    datatable MyDt=client.GetBenefitMonthlyList("052015", 3);
    

    Best regards,

    Sam

    Thursday, July 25, 2019 9:24 AM