为了测试我们创建的 Web 服务,下面拟使用一个 Windows 窗体应用程序,此应用程序将使用一个 WebReference 来引用我们的
Web 服务,有两个按钮,每个按钮执行各自的方法,下面是每个按钮的各自代码: private void button1_Click(object sender, System.EventArgs e)
{
// GetImage Method
BinaryFormatterSvc.Service1 s= new BinaryFormatterSvc.Service1();
BinaryFormatterSvc.ImageClass icc=s.GetImage(this.textBox1.Text);
byte[] byt=icc.myImage;
MemoryStream ms = new MemoryStream(byt);
Bitmap b=(Bitmap) Image.FromStream(ms);
pictureBox1.Image=b;
}
private void button2_Click(object sender, System.EventArgs e)
{
//GetImageBytes (BinaryFormatter) method
BinaryFormatterSvc.Service1 s= new BinaryFormatterSvc.Service1();
byte[] byt=s.GetImageBytes(this.textBox1.Text);
MemoryStream ms = new MemoryStream(byt);
BinaryFormatter bf= new BinaryFormatter();
ImageClass ic=(ImageClass)bf.Deserialize(ms);
MemoryStream ms2 = new MemoryStream(ic.myImage);
Bitmap b=(Bitmap) Image.FromStream(ms2);
pictureBox1.Image=b;
}
下面是方法调用后的结果,图片是我信手拿来的一张照片——在服务器上的一张名为“Pete.jpg”的图片: 逆风者
顺便提醒一下,不要忘记在我们的 Windows 窗体应用程序中添加对 ImageClass 程序集的引用,以便让我们的客户端知道怎样反序列化它所接收的类型,以及
将所接收到的类型反序列化成什么,以及还原出图像用于显示。
翻译:侯勇
地址:曲阜师范大学日照分校计算机系
邮编:276800
电话:0633-8711769E-mail:aspnetcs@eyou.com
本文章更多内容:<<上一页 - 1 - 2 |