如何刷新我的Xml Web服务? [英] How Do I Refresh My Xml Web Service?

查看:66
本文介绍了如何刷新我的Xml Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好;







我的网络服务代码在这里;



Hi everbody;



my web service code is here;

[WebMethod]
     public List<byte[]> getPicture()
     {
         List<byte[]> img = new List<byte[]>();
         string impath = @"C:\Users\vehbi\Desktop\pictures";
         foreach (string file in Directory.GetFiles(impath))
             img.Add(File.ReadAllBytes(file));

         return img;
     }





我的表格申请代码:



使用系统;

使用System.Collections.Generic;

使用System.ComponentModel;

使用System.Data;

使用System.Drawing;

使用System.Linq;

使用System.Text;

使用System.Windows.Forms;

使用System.IO;

使用System.Xml;





namespace Client

{

公共部分类Form1:表格

{

public Form1()

{

InitializeComponent();

}



ServiceReference1.Service1SoapClient deneme = new ServiceReference1.Service1SoapClient() ;





private void Form1_Load(object sender,EventArgs e)

{



}

private void button1_Click(obj ect sender,EventArgs e)

{

timer1.Start();



byte [] [] img = deneme.getPicture();









flowLayoutPanel1。 Controls.Clear();

foreach(img中的byte [] pic)

{

MemoryStream ms = new MemoryStream(pic);

PictureBox picbox = new PictureBox();

picbox.Size = new System.Drawing.Size(150,150);

picbox.Image = Image.FromStream(ms);

picbox.SizeMode = PictureBoxSizeMode.Zoom;

flowLayoutPanel1.Controls.Add(picbox);

< br $>
}



}





my问题是如何刷新我的Web服务。服务器每15分钟添加一张图片,客户必须查看添加的图片。不按button1



my form application code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;


namespace Client
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

ServiceReference1.Service1SoapClient deneme = new ServiceReference1.Service1SoapClient();


private void Form1_Load(object sender, EventArgs e)
{

}
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();

byte[][] img = deneme.getPicture();




flowLayoutPanel1.Controls.Clear();
foreach (byte[] pic in img)
{
MemoryStream ms = new MemoryStream(pic);
PictureBox picbox = new PictureBox();
picbox.Size = new System.Drawing.Size(150, 150);
picbox.Image = Image.FromStream(ms);
picbox.SizeMode = PictureBoxSizeMode.Zoom;
flowLayoutPanel1.Controls.Add(picbox);

}

}


my question is how can i refresh my web service. Server adds a picture per 15 minutes and clients has to see added pictures. without pressing button1

推荐答案

1.您应该使用计时器类 [ ^ ]。因此,通过这种方式每15分钟(或其他可以配置的值),计时器操作将自动检查,加载,然后在您的UI中显示来自您的Web服务的新图像。



2.您应该删除代码 timer1.Start(); ,然后在 Form1_Load()事件方法你必须通过设置它的时间间隔初始化你的Timer对象,更重要的是定时器事件,最后移动你的代码来获取这个事件方法中的图像,如下所示:

1.You should use Timer class[^]. So in this way on each 15 minutes (or other value that could be also configurable) the timer action will automatically check, load, then display in your UI the new images from your web service.

2.You should remove the code timer1.Start(); , then in your Form1_Load() event method you have to initialize your Timer object by setting its time interval and more important the timer event, and finally move your code that get the image in this event method like below:
private void Form1_Load(object sender, EventArgs e)
{
        // Create a timer with a 15 minutes interval.
        timer1 = new System.Timers.Timer(900000);
        // Hook up the Elapsed event for the timer.
        timer1.Elapsed += OnTimedEvent;
        timer1.Enabled = true;
}

private static void OnTimedEvent(Object source, ElapsedEventArgs e)
{
byte[][] img = deneme.getPicture();
 
flowLayoutPanel1.Controls.Clear();
foreach (byte[] pic in img)
 {
   MemoryStream ms = new MemoryStream(pic);
   PictureBox picbox = new PictureBox();
   picbox.Size = new System.Drawing.Size(150, 150);
   picbox.Image = Image.FromStream(ms);
   picbox.SizeMode = PictureBoxSizeMode.Zoom;
   flowLayoutPanel1.Controls.Add(picbox);
 }
}


这篇关于如何刷新我的Xml Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆