public class VremeZip : IXmlSerializable
{
string naziv;
string temperatura;
string zemljevid_url;
public void SetNaziv(string n)
{
naziv = n;
}
public void SetTemperatura(string n)
{
temperatura = n;
}
public void SetZemlj(string n)
{
zemljevid_url = n;
}
public string GetNaziv()
{
return naziv;
}
XmlSchema IXmlSerializable.GetSchema()
{
return null;
}
public void ReadXml(XmlReader reader)
{
throw new NotImplementedException();
}
public void WriteXml(XmlWriter writer)
{
writer.WriteElementString("string", naziv);
writer.WriteElementString("string", temperatura);
writer.WriteElementString("string", zemljevid_url);
}
}
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public VremeZip Vreme(string zip)
{
cdyne.Weather v1 = new cdyne.Weather();
VremeZip v = new VremeZip();
v.SetNaziv(v1.GetCityWeatherByZIP(zip).City);
v.SetTemperatura(v1.GetCityWeatherByZIP(zip).Temperature);
v.SetZemlj("ni urlja");
// return v1.GetCityWeatherByZIP(zip).Temperature;
return v;
}
}
这是我的asp.net Web服务代码,它返回一个VremeZip类的对象,它由3个字符串组成。
现在,我已经创建了ac#Windows Forms应用程序,我想读取该对象,并显示提供的所有信息。
我有一个文本框和一个带有click事件的按钮:
public class VremeZip
{
public string naziv { get; set; }
public string temperatura { get; set; }
public string zemljevid_url { get; set; }
}
private void button1_Click(object sender, EventArgs e)
{
vreme.WebService1 v1 = new vreme.WebService1();
VremeZip v = new VremeZip();
label1.Text = v1.Vreme(textBox1.Text);
}
但是,这只会返回第一件事。例如,如果我输入90001(洛杉矶邮政编码),它将仅返回标签中的城市,而不是所有三个字符串(名称,温度,URL)。
我无法在Windows窗体中创建新对象,而只能这样做:
VremeZip v = new VremeZip();
v = v1.Vreme(textBox1.Text);
由于出现错误,因为我的方法以某种方式返回了字符串,而不是实际的对象。
是否有可能从对象中获取所有3个字符串?
感谢提示t0mm13b,我没有设法返回整个对象,我只是重写了tostring方法并返回了一个字符串。从那时起,我将琴弦分割成不同的部分。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句