www.pudn.com > wstest.rar > WSTest.cs


/* 
 * Author : ·½Ξι 
 * Date: 2008-2-21 
 * Blog: http://www.cnblogs.com/binbin1845 
 * QQ: 32418201 
 * Email: binbin1845@126.com 
 */ 
 
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
 
namespace WSTest 
{ 
    public partial class WSTest : Form 
    { 
        public WSTest() 
        { 
            InitializeComponent(); 
            cmbAddress.Items.Add("http://localhost/EWS.UI.Service/EWSService.asmx"); 
            cmbAddress.Items.Add("http://localhost/YEA.COMOD.EWS.Service/EWSService.asmx"); 
        } 
 
        private void btnTest_Click(object sender, EventArgs e) 
        { 
            try 
            { 
                string wsAddress = cmbAddress.Text.Trim(); 
                string wsMethod = txtMethod.Text.Trim(); 
                object[] wsParameter = null; 
                if (txtParameter.Text.Trim() != "") 
                { 
                    wsParameter = txtParameter.Text.Trim().Split(','); 
                } 
                object result = WebServiceHelper.InvokeWebService(wsAddress, wsMethod, wsParameter); 
                if (result == null) 
                { 
                    txtResult.Text = "null"; 
                    dgResult.DataSource = null; 
                    return; 
                } 
                if (result.GetType().FullName == "System.Data.DataSet") 
                { 
                    DataSet ds = (DataSet)result; 
                    dgResult.DataSource = ds.Tables[0].DefaultView; 
                    txtResult.Text = ""; 
                } 
                else 
                { 
                    txtResult.Text = result.ToString(); 
                    dgResult.DataSource = null; 
                } 
 
            } 
            catch (Exception ex) 
            { 
                MessageBox.Show(ex.Message); 
            } 
        } 
    } 
}