Search code examples
c#asp.netweb-servicesdataview

ASP.NET Webservice


I may be going at this from the wrong direction. I'm fairly new to .net web services and was looking for a little help.

I have a geolocation webservice I got online and I wanted to bind the results to a listbox or a dataview but am unable too.

I've created a web proxy called net.webservicex.www that points to the webservice at.. http://www.webservicex.net/geoipservice.asmx

Here's my c# code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace web_services
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            net.webservicex.www.GeoIPService myProxy = new net.webservicex.www.GeoIPService(); // proxy object
            string ipAddress, result;

            ipAddress = txtIpAddress.Text;

            result = myProxy.GetGeoIP("64.106.166.130");
            lstResults.DataSource = result;
            lstResults.DataMember = "IP";

        }
    }
}

The error I'm recieving is Error

Cannot implicitly convert type 'web_services.net.webservicex.www.GeoIP' to 'string' at line 24

If someone could give me some tips or idea's that would be great.

Thanks! Paul


Solution

  • You don't need to put it in the result string

    lstResults.DataSource = myProxy.GetGeoIP("64.106.166.130");
    

    Since the object returned by your webservice is not enumerable, You could trick it by putting it into an a enumerable Type:

    List<web_services.net.webservicex.www.GeoIP> resultList = new List<web_services.net.webservicex.www.GeoIP>();
    resultList.Add(myProxy.GetGeoIP("64.106.166.130"));
    lstResults.DataSource = resultList;