Pass data from one server to another server with webservice using C# and VB.Net in ASP.Net

Last Reply 11 months ago By kalpesh

Posted 11 months ago


I am newer to webservice concept in .net.

I want to pass data from application1 (Server1) to application2 (Server2) using webservice.


Posted 11 months ago

Hi Waghmare,

Refer the below article for your reference to how to transfer data from one website to another the website.

How to transfer data from one website to another in ASP.Net

Also refer below link how to create WebServices.

Simple Tutorial to create WCF Service (SVC) step by step with example in ASP.Net

Form both reference link you can implement applications to transfer data from one application to another using WebServices.

Here i have created two applications one from which we call WebServices to transfer data to another application. Just you need to note you have to add exact URL of your second application with the correct port no of application.



    public class Service1 : IService1
        public void TransferData(string firstName, string lastName, string returnUrl)
            ASCIIEncoding encoding = new ASCIIEncoding();
            string data = string.Format("FirstName={0}&LastName={1}", firstName, lastName);
            byte[] bytes = encoding.GetBytes(data);
            HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(returnUrl);
            httpRequest.Method = "POST";
            httpRequest.ContentType = "application/x-www-form-urlencoded";
            httpRequest.ContentLength = bytes.Length;
            using (Stream stream = httpRequest.GetRequestStream())
                stream.Write(bytes, 0, bytes.Length);


FirstApplication (PostDataFromOneWebsiteToAnother)


        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />


    protected void Button1_Click(object sender, EventArgs e)
        Service.Service1Client client = new Service.Service1Client();
        client.TransferData("Mudassar", "Khan", "http://localhost:62949/PostDataFromOneWebsiteToAnother2/Default.aspx");


    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim client As New Service.Service1Client()
        client.TransferData("Mudassar", "Khan", "http://localhost:62949/PostDataFromOneWebsiteToAnother2/Default.aspx")
    End Sub

SecondApplication (PostDataFromOneWebsiteToAnother2)



    protected void Page_Load(object sender, EventArgs e)
        if (Request.Form.Count > 0)
            string firstName = Request.Form["FirstName"];
            string lastName = Request.Form["LastName"];


Protected Sub Page_Load(sender As Object, e As EventArgs)  Handles Me.Load
	If Request.Form.Count > 0 Then
		Dim firstName As String = Request.Form("FirstName")
		Dim lastName As String = Request.Form("LastName")
	End If
End Sub