J'ai deux applications WinForms: un 'serveur' et un 'client'. Sur le serveurExtraire des informations de 'Serveur' via WCF
private ServiceHost host;
private const string serviceEnd = "Done";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
List<string> sqlList = new List<string>();
foreach (string line in this.richTextBoxSql.Lines)
sqlList.Add(line);
SqlInfo sqlInfo = new SqlInfo(sqlList);
host = new ServiceHost(
typeof(SqlInfo),
new Uri[] { new Uri("net.pipe://localhost") });
host.AddServiceEndpoint(typeof(ISqlListing),
new NetNamedPipeBinding(),
serviceEnd);
host.Open();
}
Où
public class SqlInfo : ISqlListing
{
public SqlInfo() {}
private List<string> sqlList;
public SqlInfo(List<string> sqlList) : this()
{
this.sqlList = sqlList;
}
public List<string> PullSql()
{
return sqlList;
}
}
[ServiceContract]
public interface ISqlListing
{
[OperationContract]
List<string> PullSql();
}
Sur le client je
private ISqlListing pipeProxy { get; set; }
private const string serviceEnd = "Done";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
List<string> l = pipeProxy.PullSql();
string s = String.Empty;
foreach (string str in l)
s += str + " ";
this.richTextBoxSql.AppendText(s.ToString());
}
private void Form1_Load(object sender, EventArgs e)
{
ChannelFactory<ISqlListing> pipeFactory =
new ChannelFactory<ISqlListing>(
new NetNamedPipeBinding(),
new EndpointAddress(
String.Format("net.pipe://localhost/{0}", serviceEnd)));
pipeProxy = pipeFactory.CreateChannel();
}
Le problème est que quand je tire la List<string>
du serveur à l'aide pipeProxy.PullSql()
il appelle le constructeur par défaut public SqlInfo() {}
et le réglage sqlList = null
.
Comment puis-je obtenir ce code pour renvoyer le texte dans le RichTextBox
sur l'application du serveur?
** Comment puis-je passer une référence dans ce cas ** Je suis nouveau à cela. J'ai réussi à faire cela est une façon très alambiquée - je vais mettre à jour ma question. Merci beaucoup pour votre temps ... – MoonKnight
@Killercam J'ai mis à jour la réponse –
Thnaks beaucoup pour votre temps ... – MoonKnight