zoukankan      html  css  js  c++  java
  • 使用WSE2.0发送附件(如图片等)

    使用WSE2.0的Dime可以发送附件。

    1、服务器端与客户端都要对Microsoft.Web.Services2.dll进和引用。

    2、使用Configuration Edtion为Web服务配置Web.config,打开Configuration Edtion,在General标签内选中所有项,然后选择保存后,会提示保存为一个config 文件,保存后打开这个文件,把里面的相关内容拷入web.config

    3、web服务器端的AdvancedService.asmx文件内添加一个方法:

      /// <summary>
      /// 利用DIME传输附件
      /// </summary>
      [WebMethod]
      public string GetAttachment()
      {
       SoapContext myContext = ResponseSoapContext.Current;
       string filePath = Server.MapPath("Demo/tmpPic1.jpg");
      
       DimeAttachment dimeImage = new DimeAttachment(
        "image/jpeg",TypeFormat.MediaType,filePath);
        dimeImage.Id = "tmpPic1.jpg";

       //将新的DimeAttachment对象添加到SoapContext对象中,
       myContext.Attachments.Add(dimeImage);
       return filePath;

    }

    4、在客户端添加一个Web引用,如:Services,这里会自动产生一个代理类AdvancedServiceWse,

    总是以Wse结尾的。

    5、在客户端添加如下代码:

      private void Page_Load(object sender, System.EventArgs e)
      {
       AdvancedServiceWse asv = new AdvancedServiceWse();
       try
       {
        myString = asv.GetAttachment();
       }
       catch(Exception ex)
       {
        Response.Output.Write(调用失败!);

         return;
       }
       Bitmap myImage = new Bitmap(asv.ResponseSoapContext.Attachments[0].Stream);
       MemoryStream mStream = new MemoryStream();
       myImage.Save(mStream,ImageFormat.Jpeg);
       myImage.Dispose();

       Response.ClearContent();
       Response.ContentType = "image/jpeg";
       Response.BinaryWrite(mStream.ToArray());
       Response.End();
       
      }

    这样就可以显示出从Web服务发过来的图片了

  • 相关阅读:
    Linux 模块管理
    python 调试方法
    LFS(Linux From Scratch)学习
    Vim完全教程
    OpenSSL基础知识
    关于jiffies回绕以及time_after,time_before
    十分简便的APK反编译(Mac 版本号 具体解释)
    亚马逊是怎样颠覆商业软件高昂价格这座”柏林墙”的
    Android自己定义控件
    Android基础新手教程——4.1.1 Activity初学乍练
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/1760287.html
Copyright © 2011-2022 走看看