C# ASP.NET Web服务
我可能走错了方向。我对.NETWeb服务相当陌生,正在寻求一些帮助 我有一个在线的地理定位网站服务,我想把结果绑定到一个列表框或数据视图,但我也不能 我创建了一个名为net.webservicex.www的web代理,它指向位于..的web服务 这是我的密码 我收到的错误是错误 无法在第24行将类型“web_services.net.webservicex.www.GeoIP”隐式转换为“string” 如果有人能给我一些建议或想法,那就太好了 谢谢! 保罗 您不需要将其放入结果字符串中C# ASP.NET Web服务,c#,asp.net,web-services,dataview,C#,Asp.net,Web Services,Dataview,我可能走错了方向。我对.NETWeb服务相当陌生,正在寻求一些帮助 我有一个在线的地理定位网站服务,我想把结果绑定到一个列表框或数据视图,但我也不能 我创建了一个名为net.webservicex.www的web代理,它指向位于..的web服务 这是我的密码 我收到的错误是错误 无法在第24行将类型“web_services.net.webservicex.www.GeoIP”隐式转换为“string” 如果有人能给我一些建议或想法,那就太好了 谢谢! 保罗 您不需要将其放入结果字符串中 lst
lstResults.DataSource = myProxy.GetGeoIP("64.106.166.130");
由于Web服务返回的对象不可枚举,您可以通过将其放入可枚举类型来欺骗它:
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;
List resultList=new List();
Add(myProxy.GetGeoIP(“64.106.166.130”);
lstreults.DataSource=resultList;
您不需要将其放入结果字符串中
lstResults.DataSource = myProxy.GetGeoIP("64.106.166.130");
由于Web服务返回的对象不可枚举,您可以通过将其放入可枚举类型来欺骗它:
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;
List resultList=new List();
Add(myProxy.GetGeoIP(“64.106.166.130”);
lstreults.DataSource=resultList;
查看此web服务的wsdl,对GetGeoIP方法的调用似乎返回一个对象,而不是字符串
这就是编译器抱怨的原因。您可以将结果类型更改为它所期望的对象,也可以使用var关键字。查看此web服务的wsdl,对GetGeoIP方法的调用似乎返回一个对象,而不是字符串 这就是编译器抱怨的原因。您可以将结果的类型更改为预期的对象,也可以使用var关键字。这一行有错误:
result = myProxy.GetGeoIP("64.106.166.130");
该方法返回的对象不是字符串,而是web\u services.net.webservicex.www.GeoIP
您已将result
声明为字符串,该字符串不匹配。也许在GeoIP
类上有一个ToString()
方法。如果是,您可以将代码更改为:
string ipAddress;
web_services.net.webservicex.www.GeoIP result;
// or maybe: object result;
ipAddress = txtIpAddress.Text;
result = myProxy.GetGeoIP("64.106.166.130");
根据结果的不同
的外观,您可以将其作为您的数据源。这一行有故障:
result = myProxy.GetGeoIP("64.106.166.130");
GeoIP result;
ipAddress = "196.36.153.129";
result = myProxy.GetGeoIP("64.106.166.130");
该方法返回的对象不是字符串,而是web\u services.net.webservicex.www.GeoIP
您已将result
声明为字符串,该字符串不匹配。也许在GeoIP
类上有一个ToString()
方法。如果是,您可以将代码更改为:
string ipAddress;
web_services.net.webservicex.www.GeoIP result;
// or maybe: object result;
ipAddress = txtIpAddress.Text;
result = myProxy.GetGeoIP("64.106.166.130");
根据
result
的外观,您可以将其作为您的数据源。我是C#和.net的初学者,但以下是我解决这个问题的方法,我相信它会对像我这样的初学者有所帮助:
GeoIP result;
ipAddress = "196.36.153.129";
result = myProxy.GetGeoIP("64.106.166.130");
结果对象如下所示:
<GeoIP><ReturnCode>1</ReturnCode><IP>11.22.33.44</IP><ReturnCodeDetails>Success</ReturnCodeDetails><CountryName>Germany</CountryName><CountryCode>GER</CountryCode></GeoIP>
其中-“mygeoip”是我的Web服务名称(而不是“net.webservicex.www”)
而GeoIPService是我的名称空间
Default.aspx:
mygeoip.GeoIPService getIP = new mygeoip.GeoIPService();
string myIP = IPTextBox.Text;
GeoIPService.mygeoip.GeoIP resultList = new GeoIPService.mygeoip.GeoIP();
resultList = getIP.GetGeoIP(myIP);
sCountry.Text = resultList.CountryName;
sCountryCode.Text = resultList.CountryCode;
sIP.Text = resultList.IP;
<asp:TextBox ID="IPTextBox" runat="server"></asp:TextBox> <asp:Button
ID="GetWhois" runat="server" Text="Get Whois" onclick="GetWhois_Click" />
<p><asp:Label ID="sCountry" runat="server" Text="Country: "></asp:Label></p>
<p><asp:Label ID="sCountryCode" runat="server" Text="Country: "></asp:Label></p>
<p><asp:Label ID="sIP" runat="server" Text="Country: "></asp:Label></p>
就是这样-我希望我已经帮助过像我这样的初学者:)我是一个非常熟悉C#和.net的初学者,但下面是我解决这个问题的方法,我相信它会帮助像我这样的初学者: 结果对象如下所示:
<GeoIP><ReturnCode>1</ReturnCode><IP>11.22.33.44</IP><ReturnCodeDetails>Success</ReturnCodeDetails><CountryName>Germany</CountryName><CountryCode>GER</CountryCode></GeoIP>
其中-“mygeoip”是我的Web服务名称(而不是“net.webservicex.www”)
而GeoIPService是我的名称空间
Default.aspx:
mygeoip.GeoIPService getIP = new mygeoip.GeoIPService();
string myIP = IPTextBox.Text;
GeoIPService.mygeoip.GeoIP resultList = new GeoIPService.mygeoip.GeoIP();
resultList = getIP.GetGeoIP(myIP);
sCountry.Text = resultList.CountryName;
sCountryCode.Text = resultList.CountryCode;
sIP.Text = resultList.IP;
<asp:TextBox ID="IPTextBox" runat="server"></asp:TextBox> <asp:Button
ID="GetWhois" runat="server" Text="Get Whois" onclick="GetWhois_Click" />
<p><asp:Label ID="sCountry" runat="server" Text="Country: "></asp:Label></p>
<p><asp:Label ID="sCountryCode" runat="server" Text="Country: "></asp:Label></p>
<p><asp:Label ID="sIP" runat="server" Text="Country: "></asp:Label></p>
就这样-我希望我已经帮助过像我这样的初学者:)
[WebMethod]
公共双过程(日期时间数据,字符串值){
List podaci=GetLines(“valute.txt”);
双库尔斯=0.0;
for(int i=0;i