首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

下传图片到服务器有关问题(.net 写的WebService)下传后的base64 解析不了

2013-03-25 
上传图片到服务器问题(.net 写的WebService)上传后的base64 解析不了要做一个上传头像的功能,主要想法是通

上传图片到服务器问题(.net 写的WebService)上传后的base64 解析不了
要做一个上传头像的功能,主要想法是通过将图片转成base64 提交到.net 的WebService 然后在服务器解析保存,但是出错了下传图片到服务器有关问题(.net 写的WebService)下传后的base64 解析不了
错误是
SoapFault - faultcode: 'soap:Server' faultstring: 'System.Web.Services.Protocols.SoapException: 服务器无法处理请求。 ---> System.Runtime.Serialization.SerializationException: 输入流是无效的二进制格式。开始内容(以字节为单位)是: FF-D8-FF-E0-00-10-4A-46-49-46-00-01-01-00-00-01-00...
android 客户端主要代码:


public String upload(String fileName, String imageBuffer){
  String nameSpace = "http://tempuri.org/";
  String methodName = "UploadPhoto";
  String soapAction = "http://tempuri.org/UploadPhoto";
  String url = "http://192.168.0.102:8007/androidapi/user/uploadfilesservice.asmx";//后面加不加那个?wsdl参数影响都不大
  
  //建树webservice连接对象
  org.ksoap2.transport.HttpTransportSE transport = new HttpTransportSE(url);
  transport.debug = true;//是否是调试模式
  
  //设置连接参数
  SoapObject soapObject = new SoapObject(nameSpace,methodName);
  soapObject.addProperty("fileName", fileName);  //参数1   图片名   
      soapObject.addProperty("imageBuffer", imageBuffer);   //参数2  图片字符串   
  //soapObject.addProperty(pi);//将自定参数参加恳求对象中
      

  //设置返回参数
  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);//soap和谈版本必须用SoapEnvelope.VER11(Soap V1.1)
  envelope.dotNet = true;//重视:这个属性是对dotnetwebservice和谈的支撑,若是dotnet的webservice 不指定rpc体式格式则用true不然要用false
  envelope.bodyOut = transport;
  envelope.setOutputSoapObject(soapObject);//设置恳求参数
  //nvelope.addMapping(nameSpace,"User",user.getClass());//传对象时必须,参数namespace是webservice中指定的, name是办事器类型的名称, claszz是自定义类的类型
  
  try {
       transport.call(soapAction, envelope);
       //SoapObject sb = (SoapObject)envelope.bodyIn;//办事器返回的对象存在envelope的bodyIn中
       Object result = envelope.getResponse();
//       User us= (User)envelope.getResponse();//直接将返回值强迫转换为已知对象
//       return us.getName() + us.getAge();
       if(result!= null)
       {
       System.out.println("result---->"+result.toString());
       }
       else
       {
       System.out.println("result---->null");
       }
       
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (XmlPullParserException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch(Exception ex){


   ex.printStackTrace();
  }
  return "";
 }


方法也是网上找的

服务端.net WebService 代码
[WebMethod]
    public string UploadPhoto(string fileName, string imageBuffer)
    {
        
//保存txt
        string txtfile = "f:\\uploadfilesservice.txt";
        StreamWriter sw = new StreamWriter(txtfile, false, Encoding.UTF8);
        sw.WriteLine(imageBuffer);
        sw.Close();

        Base64ToImg(imageBuffer);
        return fileName;
        
    }

    /// <summary>
    /// 将base64 图片流转换成 图片
    /// </summary>
    /// <param name="base64Str"></param>
    private void Base64ToImg(string base64Str)
    {
        string base64 = base64Str;
        byte[] bytes = Convert.FromBase64String(base64);
        MemoryStream memStream = new MemoryStream(bytes);
        BinaryFormatter binFormatter = new BinaryFormatter();
        Image img = (Image)binFormatter.Deserialize(memStream);
        img.Save("f:\\aa.jpg");
    }





求大神帮助,或给个android 上传图片 .net WebService 的Demo
[解决办法]
我来帮你,  兄弟, 能不能发一份demo给我?  我也在做这一块。 使用webservice.   纠结的是客户端传数据传不过去。  rpc.addProperty("str", "张三");    “张三”传不过去。
[解决办法]
是不是中英文输入法的问题呀
[解决办法]
是不是图片字节流转base64  编码出问题了

热点排行