今TCP/IPでクライアントとサーバーの通信をしています。
クライアントのClassをシリアライズし、サーバーに送りたいのですがやり方がイマイチわかりません。
クライアント側
C#
1Sample sampleData = new Samle(); 2 3public static void WriteBinaryData(object sampleDate) 4 { 5 TcpClient client = new TcpClient(); 6 client.Connect("127.0.0.1", 9000); 7 NetworkStream stream = client.GetStream(); 8 9 // BinaryFormatterオブジェクト生成 10 BinaryFormatter formatter = new BinaryFormatter(); 11 formatter.Serialize(stream, sampleData); }
でシリアライズしました。
下記がシリアライズ対象のクラスです。(中身が""なのは気にしないでください。)
C#
1[Serializable] 2 class Sample 3 { 4 public string maker = ""; 5 public string name = ""; 6 public string bodytype = ""; 7 public string model = ""; 8 public string distance = ""; 9 public string cc = ""; 10 public string transmission = ""; 11 public string color = ""; 12 public string price = ""; 13 }
サーバー側のデシリアライズメソッド(抜粋)
C#
1 public void Receive(NetworkStream stream) 2 { 3 BinaryFormatter formatter = new BinaryFormatter(); 4 Sample sampleDate = new Sample(); 5 sampleDate = (Sample)formatter.Deserialize(stream); 6 }
サーバー側も同じように下記のクラスを作りました。
C#
1[Serializable] 2 class Sample 3 { 4 public string maker = ""; 5 public string name = ""; 6 public string bodytype = ""; 7 public string model = ""; 8 public string distance = ""; 9 public string cc = ""; 10 public string transmission = ""; 11 public string color = ""; 12 public string price = ""; 13 }
そうすると{"アセンブリ 'クライアント, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' が見つかりません。"}と出てきます。
どうすればデシリアライズがうまくいくのでしょうか?
またDLL??がどうこうと参考したサイトには記載されていますがどういうことでしょうか?
無知で全然わかっておりませんがよろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/06/13 10:39
2017/06/14 01:11
退会済みユーザー
2017/06/14 02:32
2017/06/14 02:37
退会済みユーザー
2017/06/14 02:45
2017/06/14 02:58
退会済みユーザー
2017/06/14 03:24 編集