欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

WebService传XML 简单实例

程序员文章站 2023-01-04 08:33:06
webservice传xml 简单实例 传送     [webmethod] public xmldatadocume...

webservice传xml 简单实例

传送

    [webmethod]

 public xmldatadocument getsiteadata(string assignname)
  {
    xmldatadocument xd = new xmldatadocument();
    dataset ds = businesswork.businessworkdataset("treeview1");

      xd = new xmldatadocument(ds);
      xmlnode root1 = xd.documentelement;
      xmlnodelist roots = root1.selectnodes("url");
      foreach (xmlnode roota in roots) //为所有元素加上站点名称标记
      {
        xmlelement link = xd.createelement("sitename");
        link.innertext = configurationsettings.appsettings["sitename"].tostring();
        roota.appendchild(link);
      }
    return xd;
  }

异步调用

  iasyncresult ar1;
    iasyncresult ar2;

    localhost.webservice servicea = new localhost.webservice();
    xmlnode xmlnode1;
    xmlnode xmlnode2;


    ////直接调用
    //xmlnode1 = servicea.getsiteadata("2");
    //异步调用
    ar1 = servicea.begingetsiteadata("3", null, null);
    ar2 = servicea.begingetsiteadata("2", null, null);
    xmlnode1 = servicea.endgetsiteadata(ar1);
    xmlnode2 = servicea.endgetsiteadata(ar2);

    stringbuilder xmlstring1;
    xmlstring1 = new stringbuilder(xmlnode1.outerxml);

    xmldatadocument xd = new xmldatadocument();
    xd.loadxml(xmlstring1.tostring());

    dataset ds = new dataset();
    ds.readxml(new xmlnodereader(xd));
    gridview1.datasource = ds.tables[0];
    gridview1.databind();

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!