Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ijust create a code for sending to asmx file but I don't know how I get the data to my textbox

C#
using System;
using System.Net;
using System.Text;
using System.IO;
using System.Web;
using System.Collections.Specialized;
using System.Windows.Forms;

namespace Niles_Money_Transfer
{
    class GetClient
    {
        /*
         * The API's response variables
         */
        private string response;
        public string Response
        {
            get { return response; }
            set { response = value; }
        }

        /*
         * The server address of the GetClient API
         */
        private string server;
        public string Server
        {
            get { return server; }
            set { server = value; }
        }


        /*
        * Transfer Name
        */
        private string myTransfer;
        public string MyTransfer
        {
            get { return myTransfer; }
            set { myTransfer = value; }
        }


        /*
        * The data that will be sent to the GetClient API
        */
        private string dataToSend;
        public string DataToSend
        {
            get { return dataToSend; }
            set { dataToSend = value; }
        }

        /*
         * constructor
         * 
         * Constructs a GetClient object
         * 
         * @param string strUserName Your username
         
         */
        public GetClient(string strUsername)
        {
            myTransfer = strUsername;
            dataToSend = string.Empty;
        }

        /*
        * GetClient::buildPostVariables()
        * 
        * Builds an URL encoded post string which contains the variables to be 
        * sent to the API in the correct format. 
        * 
        * @param string $strCurrency 3 letter ISO-4217 currency code.
        * 
        * @return string The URL encoded post string
        */
        public string BuildPostVariables(string strRecord)
        {
            StringBuilder sbDataToSend = new StringBuilder();
            sbDataToSend.AppendFormat("TRANSFER={0}",  HttpUtility.UrlEncode(myTransfer), HttpUtility.UrlEncode((string)strRecord));
            dataToSend = sbDataToSend.ToString();
            return dataToSend;
        }

        public string PostData()
        {
            string response = string.Empty;

            StreamWriter myWriter = null;
            HttpWebRequest objRequest = null;

            try
            {
                // send the post
                objRequest = (HttpWebRequest)WebRequest.Create(server);
                objRequest.Method = "POST";
                objRequest.ContentLength = dataToSend.Length;
                objRequest.ContentType = "application/x-www-form-urlencoded";

                myWriter = new StreamWriter(objRequest.GetRequestStream());
                myWriter.Write(dataToSend);
                myWriter.Close();

                // read the response
                HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
                StreamReader sr = new StreamReader(objResponse.GetResponseStream());
                string result = "";
                string strTemp = "";
                bool flag = true;
                while (flag)
                {
                    strTemp = sr.ReadLine();
                    if (strTemp != null)
                    {
                        result += strTemp;
                    }
                    else
                    {
                        flag = false;
                    }
                }

                response = result;
                // decode the response string
                response = HttpUtility.UrlDecode(response);
                sr.Close();
            }
            catch (UriFormatException e)
            {
                throw (e); 
            }
            catch (Exception e)
            {
                throw (e);
            }
            finally
            {
                if (myWriter != null)
                {
                    myWriter.Close();
                }
            }

            return response;
        }
    }

}


C#
/*
             * test GetClient API
             */
            GetClient objGetBalanceClient = new GetClient("'" + textBox9.Text + "'");
            objGetBalanceClient.Server = "http://localhost:61016/WebService1.asmx";
            string strPostString = objGetBalanceClient.BuildPostVariables("");
            objGetBalanceClient.Response = objGetBalanceClient.PostData();

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Web.Script.Services;
using System.Xml;

namespace WebApplication1
 
{
 
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // [System.Web.Script.Services.ScriptService]
    public class AutoComplete : System.Web.Services.WebService
    {
 

 
        private void connectoToMySql(string name)
        {
 
            string connString = "SERVER=localhost" + ";" +
                "DATABASE=money;" +
                "UID=root;" +
                "PASSWORD=password;";

            MySqlConnection conn = null;
            MySqlDataReader rdr = null;

            try
            {
                conn = new MySqlConnection(connString);
                conn.Open();

                string stm = "SELECT * FROM Add_Number Where E-mail = '" + name + "'";
                MySqlCommand cmd = new MySqlCommand(stm, conn);
                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    Console.WriteLine(rdr.GetInt32(0) + ": "
                        + rdr.GetString(1));
                }

            }
            catch (MySqlException ex)
            {
                Console.WriteLine("Error: {0}", ex.ToString());

            }
            finally
            {
                if (rdr != null)
                {
                    rdr.Close();
                }

                if (conn != null)
                {
                    conn.Close();
                }

            }

        }

    }
}
Posted
Updated 26-Dec-14 7:44am
v8
Comments
ZurdoDev 26-Dec-14 10:35am    
Where exactly are you stuck? That's a lot of code and it sounds like all you need to do is put the return value into a textbox which seems very trivial.
elmutasim23 26-Dec-14 10:45am    
the textbox that what I am searching for the string strPostString = objGetBalanceClient.BuildPostVariables("");
elmutasim23 27-Dec-14 9:52am    
I find this in codeplex http://wsdlgenerator.codeplex.com/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900