質問編集履歴
3
訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,8 +3,6 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
クライアントのClassをシリアライズし、サーバーに送りたいのですがやり方がイマイチわかりません。
|
6
|
-
|
7
|
-
NetWorkStreamクラスを使用して行うと思うのですが、参考になるサイトをいろいろ見てもできませんでした・・・
|
8
6
|
|
9
7
|
|
10
8
|
|
2
訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -127,3 +127,7 @@
|
|
127
127
|
|
128
128
|
|
129
129
|
どうすればデシリアライズがうまくいくのでしょうか?
|
130
|
+
|
131
|
+
またDLL??がどうこうと参考したサイトには記載されていますがどういうことでしょうか?
|
132
|
+
|
133
|
+
無知で全然わかっておりませんがよろしくお願いいたします。
|
1
訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -9,8 +9,6 @@
|
|
9
9
|
|
10
10
|
|
11
11
|
クライアント側
|
12
|
-
|
13
|
-
Calss Sampleをサーバーに送信したい場合どのようなコードになるのでしょうか?
|
14
12
|
|
15
13
|
```C#
|
16
14
|
|
@@ -26,24 +24,106 @@
|
|
26
24
|
|
27
25
|
client.Connect("127.0.0.1", 9000);
|
28
26
|
|
27
|
+
NetworkStream stream = client.GetStream();
|
28
|
+
|
29
29
|
|
30
30
|
|
31
31
|
// BinaryFormatterオブジェクト生成
|
32
32
|
|
33
33
|
BinaryFormatter formatter = new BinaryFormatter();
|
34
34
|
|
35
|
+
formatter.Serialize(stream, sampleData); }
|
35
36
|
|
37
|
+
```
|
36
38
|
|
37
|
-
|
39
|
+
でシリアライズしました。
|
38
40
|
|
41
|
+
下記がシリアライズ対象のクラスです。(中身が""なのは気にしないでください。)
|
42
|
+
|
43
|
+
```C#
|
44
|
+
|
45
|
+
[Serializable]
|
46
|
+
|
47
|
+
class Sample
|
48
|
+
|
49
|
+
{
|
50
|
+
|
51
|
+
public string maker = "";
|
52
|
+
|
53
|
+
public string name = "";
|
54
|
+
|
55
|
+
public string bodytype = "";
|
56
|
+
|
57
|
+
public string model = "";
|
58
|
+
|
59
|
+
public string distance = "";
|
60
|
+
|
61
|
+
public string cc = "";
|
62
|
+
|
63
|
+
public string transmission = "";
|
64
|
+
|
65
|
+
public string color = "";
|
66
|
+
|
67
|
+
public string price = "";
|
68
|
+
|
39
|
-
|
69
|
+
}
|
40
70
|
|
41
71
|
```
|
42
72
|
|
43
73
|
|
44
74
|
|
75
|
+
サーバー側のデシリアライズメソッド(抜粋)
|
76
|
+
|
77
|
+
```C#
|
78
|
+
|
79
|
+
public void Receive(NetworkStream stream)
|
80
|
+
|
81
|
+
{
|
82
|
+
|
83
|
+
BinaryFormatter formatter = new BinaryFormatter();
|
84
|
+
|
85
|
+
Sample sampleDate = new Sample();
|
86
|
+
|
87
|
+
sampleDate = (Sample)formatter.Deserialize(stream);
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
```
|
92
|
+
|
93
|
+
サーバー側も同じように下記のクラスを作りました。
|
94
|
+
|
95
|
+
```C#
|
96
|
+
|
97
|
+
[Serializable]
|
98
|
+
|
45
|
-
|
99
|
+
class Sample
|
100
|
+
|
101
|
+
{
|
102
|
+
|
103
|
+
public string maker = "";
|
104
|
+
|
105
|
+
public string name = "";
|
106
|
+
|
107
|
+
public string bodytype = "";
|
108
|
+
|
109
|
+
public string model = "";
|
110
|
+
|
111
|
+
public string distance = "";
|
112
|
+
|
113
|
+
public string cc = "";
|
114
|
+
|
115
|
+
public string transmission = "";
|
116
|
+
|
117
|
+
public string color = "";
|
118
|
+
|
119
|
+
public string price = "";
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
```
|
124
|
+
|
125
|
+
そうすると{"アセンブリ 'クライアント, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' が見つかりません。"}と出てきます。
|
46
126
|
|
47
127
|
|
48
128
|
|
49
|
-
|
129
|
+
どうすればデシリアライズがうまくいくのでしょうか?
|