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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值