android調用.Net WebService傳遞byte[]
android端代碼:
SoapObject request = new SoapObject(Constant.NAMESPACE, "XXXX");<br />// request.addProperty("strIn", "123456");<br />byte[] byValue;<br />byValue = "Hello world".getBytes();<br />String strByte = Base64.encode(byValue);<br />request.addProperty("condtion", strByte);</p><p>SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(<br />SoapEnvelope.VER11);<br />envelope.dotNet = true;<br />envelope.setOutputSoapObject(request);<br />new MarshalBase64().register(envelope);</p><p>// 發出請求<br />AndroidHttpTransport aht = new AndroidHttpTransport(Constant.URL);<br />// aht.debug = true;</p><p>try {<br />aht.call(Constant.SOAP_ACTION + "XXXX", envelope);<br />} catch (IOException e) {<br />// TODO Auto-generated catch block<br />e.printStackTrace();<br />} catch (XmlPullParserException e) {<br />// TODO Auto-generated catch block<br />e.printStackTrace();<br />}<br />try {<br />Object obj = envelope.getResponse();<br />System.out.println(String.valueOf(obj));<br />} catch (SoapFault e) {<br />// TODO Auto-generated catch block<br />e.printStackTrace();<br />}
.NET端:
[WebMethod(Description = "測試byte[]")]<br /> public string XXXX(string condtion)<br /> {<br /> byte[] buffer = Convert.FromBase64String(condtion);//拿到byte[],你可以為所欲為了<br /> return Encoding.UTF8.GetString(buffer); //類型轉換很重要<br /> }