欢迎光临
我们一直在努力

使用wse(Web Services Enhancements )把服务器端的文件传到客户端-ASP教程,客户端相关

建站超值云服务器,限时71元/月

 

比如说,现在站点a有个附件想传给站点b,我们就可以用wse来传。
在服务器端的webservice文件service1.asmx中写入webmethod:
这个是取附件的方法:
[webmethod]
  public void getattachment()
   {
    // 获取 soapcontext 作为响应消息
    soapcontext mycontext = httpsoapcontext.responsecontext;
   
   // 字符串,表示附件的文件名和路径。
   string filepath = @”c:\my documents\1.txt”;

   // 使用文件名来创建新的 dime 附件,
   // 并通过 mime 媒体类型
   // 来指定附件编码。
   dimeattachment dimeimage = new dimeattachment(
    “text/xml”, typeformatenum.mediatype,
    filepath);
   
   // 指定给 dime 记录的 id 属性。
   dimeimage.id = “1.txt”;

   // 将新的 dimeattachment 对象添加到 soapcontext 对象中。
   mycontext.attachments.add(dimeimage);

   }

在客户端的web站点下载附件,并写入到新的文件中:
private void downattachment()
  {
   //service1wse : microsoft.web.services.webservicesclientprotocol    这里的service1继承wse 中的类
   service1wse sw=new service1wse(); 
   //从webservice中获取附件
   sw.getattachment();
   //得到附件的流
   stream str=sw.responsesoapcontext.attachments[0].stream;
   int length=(int)str.length;
   byte[] attdata=new byte[length];
   //把附件的流写入byte中
   str.read(attdata,0,length);

   //创建新文件
   fileinfo fi=new fileinfo(@”c:\”+sw.responsesoapcontext.attachments[0].id);
   filestream fs=fi.create();
   //把byte写入新文件中
   fs.write(attdata,0,length);
   fs.flush();
   fs.close();
  }

注意:在webservice站点和客户端website站点的web.config中system.web节下加:
<webservices>
      <soapextensiontypes>
        <add type=”microsoft.web.services.webservicesextension, microsoft.web.services, version=1.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35″ priority=”1″ group=”0″ />
      </soapextensiontypes>
    </webservices>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 使用wse(Web Services Enhancements )把服务器端的文件传到客户端-ASP教程,客户端相关
分享到: 更多 (0)

相关推荐

  • 暂无文章