Dokładnie chodzi o to, że chcę wczytać do ListBoxa tekst ze strony internetowej. W tym celu użyłem Html Agility Pack. Wykorzystując samą aplikację okienkową wszystko działa tak jakbym chciał, ale jeśli przychodzi do napisania klienta, to zaczynam się gubić. Konkretnie mam problem z przekazaniem tego tekstu z usługi do klienta, męczę się z tym już dłuższy czas a rozwiązania nie znalazłem do tej pory.
Jedyną pozycją jaka pojawia się w ListBoxie jest "RMKlient.RMServiceRef.Aktualnosci".
Poniżej zamieszczam kod:
Interfejs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace RMNews
{
<ServiceContract>
public interface IRMInterface
{
<OperationContract>
Aktualnosci Wyswietl(string tekst);
}
}
Usługa:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using HtmlAgilityPack;
namespace RMNews
{
public class Service1 : IRMInterface
{
public Aktualnosci Wyswietl(string naglowek)
{
Aktualnosci tekscik = new Aktualnosci(naglowek);
string Url = "http://www.realmadrid.pl/index.php?co=aktualnosci";
HtmlWeb web = new HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = web.Load(Url);
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//h2"))
naglowek = node.InnerText;
return tekscik;
}
}
}
Klasa Aktualnosci:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
namespace RMNews
{
<DataContract>
public class Aktualnosci
{
<DataMember>
public string news;
public Aktualnosci(string tekst)
{
this.news = tekst;
}
}
}
I klient:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RMKlient
{
public partial class Form1 : Form
{
public RMServiceRef.RMInterfaceClient klient;
public Form1()
{
InitializeComponent();
klient = new RMServiceRef.RMInterfaceClient();
klient.Open();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add(klient.Wyswietl());
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
}
}
Proszę o pomoc z rozwiązaniem tego problemu. Z góry dzięki ;)