资源简介

连接webservice数据接口,获取数据的小例子,这里使用的是winfrom来展示,主要内容是怎么获取webservice的数据,同时怎么解析。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
using System.xml;

namespace Solution_GetData_Winform
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender EventArgs e)
        {
            
        }

        /// 
        /// WebService返回的是xmlDocument
        /// 

        private DataSet GetDataSetFromWebServiceByxmlDocument(string serviceUrl)
        {
            string webserviceUrl = serviceUrl;
            string charSet = “utf-8“;
            DataSet ds = new DataSet();
            try
            {
                string pageContent = GetWebServiceContent(webserviceUrl charSet);
                xmlDocument xd = new xmlDocument();
                xd.Loadxml(pageContent);

                ds.Readxml(new xmlNodeReader(xd));
            }
            catch (Exception err)
            {
                Console.WriteLine(err.ToString());
            }
            return ds;
        }

        /// 
        /// WebService返回的是Byte数组
        /// 这个方法我没有测试,不过问题应该不大。。。。。
        /// 

        static void GetDataSetFromWebServiceByteArray(string webserviceUrl)
        {
            
            string charSet = “utf-8“;

            try
            {
                string pageContent = GetWebServiceContent(webserviceUrl charSet);
           
                //加载文档
                xmlDocument xd = new xmlDocument();
                xd.Loadxml(pageContent);
                byte[] bytes = Convert.Frombase64String(xd.DocumentElement.InnerText);
                //因为WebService方法中序列化过,所以这里需要反序列化
                MemoryStream ms = new MemoryStream(bytes);
                System.Runtime.Serialization.IFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                object obj = bf.Deserialize(ms);
                DataSet dataset = obj as DataSet;
                ms.Close();
            }
            catch (Exception err)
            {
                Console.WriteLine(err.ToString());
            }
        }



        /// 
        /// 将Byte[]转换为DataSet
        /// 反序列化了一下
        /// 

        /// 
        /// 
        static DataSet GetDataSetByUnCompressByte(byte[] data)
        {
            MemoryStream ms = new MemoryStream(data);
            System.Runtime.Serialization.IFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            object obj = bf.Deserialize(ms);
            DataSet dsResult = (DataSet)obj;
            ms.Close();
            return dsResult;
        }



        /// 

        /// 请求

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      12288  2014-03-08 10:48  复件 Solution_GetData_Winform\Solution_GetData_Winform\bin\Debug\Solution_GetData_Winform.exe

     文件      24064  2014-03-08 10:48  复件 Solution_GetData_Winform\Solution_GetData_Winform\bin\Debug\Solution_GetData_Winform.pdb

     文件      11608  2014-03-08 10:46  复件 Solution_GetData_Winform\Solution_GetData_Winform\bin\Debug\Solution_GetData_Winform.vshost.exe

     文件        490  2010-03-17 22:39  复件 Solution_GetData_Winform\Solution_GetData_Winform\bin\Debug\Solution_GetData_Winform.vshost.exe.manifest

     文件      10240  2014-03-07 11:14  复件 Solution_GetData_Winform\Solution_GetData_Winform\bin\Debug_获取数据\Solution_GetData_Winform.exe

     文件      22016  2014-03-07 11:14  复件 Solution_GetData_Winform\Solution_GetData_Winform\bin\Debug_获取数据\Solution_GetData_Winform.pdb

     文件      11608  2014-03-07 11:13  复件 Solution_GetData_Winform\Solution_GetData_Winform\bin\Debug_获取数据\Solution_GetData_Winform.vshost.exe

     文件        490  2010-03-17 22:39  复件 Solution_GetData_Winform\Solution_GetData_Winform\bin\Debug_获取数据\Solution_GetData_Winform.vshost.exe.manifest

     文件       4988  2014-03-08 10:47  复件 Solution_GetData_Winform\Solution_GetData_Winform\Form1.cs

     文件       4979  2014-03-07 15:01  复件 Solution_GetData_Winform\Solution_GetData_Winform\Form1.Designer.cs

     文件       5817  2014-03-07 15:01  复件 Solution_GetData_Winform\Solution_GetData_Winform\Form1.resx

     文件       5407  2014-03-08 10:48  复件 Solution_GetData_Winform\Solution_GetData_Winform\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1248  2014-03-08 10:48  复件 Solution_GetData_Winform\Solution_GetData_Winform\obj\x86\Debug\GenerateResource-ResGen.read.1.tlog

     文件       1618  2014-03-08 10:48  复件 Solution_GetData_Winform\Solution_GetData_Winform\obj\x86\Debug\GenerateResource-ResGen.write.1.tlog

     文件       2139  2014-03-08 10:48  复件 Solution_GetData_Winform\Solution_GetData_Winform\obj\x86\Debug\Solution_GetData_Winform.csproj.FileListAbsolute.txt

     文件      12288  2014-03-08 10:48  复件 Solution_GetData_Winform\Solution_GetData_Winform\obj\x86\Debug\Solution_GetData_Winform.exe

     文件        180  2014-03-08 10:48  复件 Solution_GetData_Winform\Solution_GetData_Winform\obj\x86\Debug\Solution_GetData_Winform.Form1.resources

     文件      24064  2014-03-08 10:48  复件 Solution_GetData_Winform\Solution_GetData_Winform\obj\x86\Debug\Solution_GetData_Winform.pdb

     文件        180  2014-03-08 10:48  复件 Solution_GetData_Winform\Solution_GetData_Winform\obj\x86\Debug\Solution_GetData_Winform.Properties.Resources.resources

     文件        485  2014-03-07 11:07  复件 Solution_GetData_Winform\Solution_GetData_Winform\Program.cs

     文件       1446  2014-03-07 11:07  复件 Solution_GetData_Winform\Solution_GetData_Winform\Properties\AssemblyInfo.cs

     文件       2898  2014-03-07 11:07  复件 Solution_GetData_Winform\Solution_GetData_Winform\Properties\Resources.Designer.cs

     文件       5612  2014-03-07 11:07  复件 Solution_GetData_Winform\Solution_GetData_Winform\Properties\Resources.resx

     文件       1109  2014-03-07 11:07  复件 Solution_GetData_Winform\Solution_GetData_Winform\Properties\Settings.Designer.cs

     文件        249  2014-03-07 11:07  复件 Solution_GetData_Winform\Solution_GetData_Winform\Properties\Settings.settings

     文件       3455  2014-03-07 11:09  复件 Solution_GetData_Winform\Solution_GetData_Winform\Solution_GetData_Winform.csproj

     文件        914  2014-03-07 11:07  复件 Solution_GetData_Winform\Solution_GetData_Winform.sln

    ..A..H.     17408  2014-03-07 16:58  复件 Solution_GetData_Winform\Solution_GetData_Winform.suo

     文件          8  2014-03-07 16:58  复件 Solution_GetData_Winform\_ReSharper.Solution_GetData_Winform\AspFileDataCache.dat

     文件          4  2014-03-08 10:46  复件 Solution_GetData_Winform\_ReSharper.Solution_GetData_Winform\BuildscriptCache\.crc

............此处省略190个文件信息

评论

共有 条评论