I am able to show the MessageBox to display the data each time the data is being updated. But I want to display all those data in a TextBox.
I understand that [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
UseSynchronizationContext = false)]
Must be set and I need to do my own marshalling.
The code is below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ServiceModel;
//using SendingBytesServiceContract;
using System.Windows.Threading;
using System.ComponentModel;
namespace SubscriberONE_GUI
{
///
/// Interaction logic for MainWindow.xaml
///
[ServiceContract]
public interface ISendingBytes
{
[OperationContract(IsOneWay = true)]
void Sending_ByteArray(byte[] data);
}
public class SendingBytesImpl : ISendingBytes
{
public void Sending_ByteArray(byte[] data)
{
string output_byte = Conversion.ByteArrayToHexString(data);
MessageBox.Show(output_byte);
//textBox1.Text = Conversion.ByteArrayToHexString(data);
}
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, UseSynchronizationContext = false)]
public partial class SubscriberONE : Window, ISendingBytes
{
ServiceHost svc = new ServiceHost(typeof(SendingBytesImpl));
public SubscriberONE()
{
InitializeComponent();
svc.Open();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
}
private void Window_Closed(object sender, EventArgs e)
{
svc.Close();
}
}
}
Benjamin KemnerPosted Jul 18, 2011, 9:11 AM
public void Sending_ByteArray(byte[] data)
{
if (!textBox1.Dispatcher.CheckAccess()){ // invoke necessary?
textBox1.Dispatcher.Invoke ( (Action)delegate { Sending_ByteArray(data); });
return;
}
string output_byte = Conversion.ByteArrayToHexString(data);
textBox1.Text = Conversion.ByteArrayToHexString(data);
}