android调用.Net WebService传递byte[]
android端代码:
SoapObject request = new SoapObject(Constant.NAMESPACE, "XXXX"); // request.addProperty("strIn", "123456"); byte[] byValue; byValue = "Hello world".getBytes(); String strByte = Base64.encode(byValue); request.addProperty("condtion", strByte); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); new MarshalBase64().register(envelope); // 发出请求 AndroidHttpTransport aht = new AndroidHttpTransport(Constant.URL); // aht.debug = true; try { aht.call(Constant.SOAP_ACTION + "XXXX", envelope); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (XmlPullParserException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { Object obj = envelope.getResponse(); System.out.println(String.valueOf(obj)); } catch (SoapFault e) { // TODO Auto-generated catch block e.printStackTrace(); }
.NET端:
[WebMethod(Description = "测试byte[]")] public string XXXX(string condtion) { byte[] buffer = Convert.FromBase64String(condtion);//拿到byte[],你可以为所欲为了 return Encoding.UTF8.GetString(buffer); //类型转换很重要 }