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服务发过来的图片了

  • 相关阅读:
    Spring IOC(二)
    Spring组件注册
    第六章:随机数和expect
    第二十一节:异常处理
    第二十节:基础知识阶段复习
    LVM逻辑卷管理
    第十九节:类的装饰器和数据描述符的应用
    第十八节:上下文管理协议
    第十七节:数据描述符
    第十六节:内置函数补充
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/1760287.html
Copyright © 2011-2022 走看看