locked
Binding data from a web service to a Windows Forms App RRS feed

  • Question

  • Hello,

    I want to add a from a online web service, after I pasted the URL it displayed me the available service, and I created a service reference called ServiceReference1.  Now I don't know if this service can be bound to Form designer. If yes, how? 

    Do I need to configure it manually in order to display data. The main intent on creating this windows form app is to display updated currency conversion rates in a table view.

    I have searched online on how to do this , but I haven't found any successful article yet.

    This is the first time that i try to get data from a web service, so I am a newbie on "web service for WinForms" .

    Am I trying to do this in a totally wrong way? 

    Here is the web service URL:

    http://www.webservicex.net/CurrencyConvertor.asmx?WSDL



    Admir

    Friday, January 15, 2016 2:28 PM

Answers

All replies

  • There's rather more to it than that.

    You can't directly bind to a web service.

    At the very least you need to involve a bindingsource.

    Take a look at this for a simple example:

    https://msdn.microsoft.com/en-us/library/ff855828%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

    Note the

    public void Form1_Load(object sender, EventArgs e)
    {
    	BindingSource1.DataSource = typeof(USPSAddress);
    	textBox1.DataBindings.Add("Text", this.BindingSource1, "FullZIP", true);
    }


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    • Marked as answer by admiri92 Wednesday, January 20, 2016 7:52 AM
    Friday, January 15, 2016 4:59 PM
  • Hi admiri92,

    I have built a webservice sample and it works well.

    Here is the code:

            //in webservice
    
            [WebMethod]
    
            public string GetRemoteString()
    
            {
    
                return "test";
    
            }
    
            [WebMethod]
    
            public int GetRemoteInt()
    
            {
    
                return 123;
    
            }
    
            [WebMethod]
    
            public float GetRemotefloat()
    
            {
    
                return 1.23f;
    
            }
    
            //in form
    
            ServiceReference1.MyServiceSoapClient myclien = new MyServiceSoapClient();
    
            string str = myclien.GetRemoteString();
    
            int tmp = myclien.GetRemoteInt();
    
            float fo = myclien.GetRemotefloat();
    

    Maybe you could refer to the following link, there are some samples:

    http://www.codeproject.com/Articles/421725/ASP-NET-Real-time-Currency-Converter-using-API-Goo

    if you want know more about webservice, you could read the following link:

    https://msdn.microsoft.com/en-us/library/8wbhsy70(v=vs.90).aspx

    Regards,

    Moonlight,

    Wednesday, January 20, 2016 9:18 AM