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

  • 相关阅读:
    [Tutorial] Using the RasPi as a WiFi hostspot
    Turn Your Raspberry Pi Into a WiFi Hotspot with Edimax Nano USB EW-7811Un (RTL8188CUS chipset)
    RPI-Wireless-Hotspot
    将树莓派Raspberry Pi设置为无线路由器(WiFi热点AP,RTL8188CUS芯片)
    java的动态代理机制详解
    ant -verbose -debug ...
    各个版本的spring jar包
    挑战树莓派:谁才是Geek最爱的开发板?
    RPi Debian Auto Login
    IP查找工具——angry IP Scanner
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/1760287.html
Copyright © 2020-2023  润新知