2016-05-02 6 views
0
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つの文字列で構成されています。asp.net WebサービスとWindowsフォームのオブジェクトの返却と読み取り

今、私はc#windowsフォームアプリケーションを作成しました。そのオブジェクトを読み込み、提供されたすべての情報を表示します。

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(ロサンゼルスの郵便番号)を入力すると、3つの文字列(名前、温度、URL)の代わりに、自分のラベルの都市だけが返されます。

私は私のWindowsフォームに新しいオブジェクトを作成し、ちょうど行うことはできません。

VremeZip v = new VremeZip(); 
v = v1.Vreme(textBox1.Text); 

何とか私の方法は、文字列ではなく、実際のオブジェクトを返しますので、私は、エラーを取得しているため。

オブジェクトから3つの文字列をすべて取得できますか?

+0

まず、あなたのwinformsコードで宣言された 'VremeZip'クラスがあります。また、 'IXmlSerializable'を継承していますか?結合文字列を取得するには、 'VremeZip'クラスで' ToString() 'オーバーライドを作成します。 – t0mm13b

+0

IXmlSerializableは、asp.net Webサービスがxmlコードを返すので、それをシリアル化するクラスに過ぎません。 たとえば、文字列を返すと、ちょうど温度: return v1.GetCityWeatherByZIP(zip)。温度; それが今ないとして、それはオブジェクトを返すのであれば基本的に、それは私がしようとしている CityName // Naziv 温度 zemljevid_url> を返します「温度」 Domi

+0

を返します。 winformsで私のクラスにすべての情報を取得してください – Domi

答えて

0

ヒントt0mm13bをいただきありがとうございます。私はオブジェクト全体を返すことはできませんでした。私はtostringメソッドをオーバーライドして1つの文字列を返しました。それから、私は弦を別々の部分に分割しました。

関連する問題