ASP.NET web服务 [英] ASP.NET Webservice

查看:102
本文介绍了ASP.NET web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在此从错误的方向走了。我是相当新的.NET Web服务,并寻求一点帮助。

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.

我有一个web服务的地理定位我在网上了,我想结合的结果,一个列表框或数据视图,但我不能太。

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.

我在.. HTTP创建的Web代理名为net.webservicex.www指向Web服务://www.webservicex.net/geoipservice.asmx

下面是我的C#code。

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";

        }
    }
}

我recieving的错误是错误

The error I'm recieving is Error

在第24行无法隐式转换类型'web_services.net.webservicex.www.GeoIP'到'字符串'

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.

谢谢!
保罗

推荐答案

<击>
你不需要把它在结果字符串

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

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

由于你的web服务返回的对象是不可枚举,您可以通过将其加入到一个枚举类型绝招吧:

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;

这篇关于ASP.NET web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆