I use the following code to upload a photo from Android phone.
b1.setOnClickListener (New OnListListener) {@Override Click Public Zero (see V) {String NAMESPACE = "http://tempuri.org/"; String URL = "http : //mywebservice.asmx "; string SOAP_ACTION =" http: / /tempuri.org/ "; try {SoapObject so = new SoapObject (NAMESPACE," insertPicture "); so.addProperty (" binPicture ", array); SoapSerializationEnvelope SSE = new SoapSerializationEnvelope (SoapEnvelope.VER11); sse.dotNet truth =; sse.setOutputSoapObject (so); Toast.makeText (getApplicationContext (), new uploadPic (implementation (SSE) .Get ()), Toast.LENGTH_LONG.). Show ();} hold (exception e) {toast.makeText (getApplicationContext (), e.getMessage () + "error", toast.LNNHNH_LOG). A. ();}}}); } Public stable byte [] StreamToibets (inputstream) {Bytereunputstream OS = New Bytereon OutputStream (1024); Byte [] buffer = new byte [1024]; Int len; Try {while ((lane = read.buffer) gt; = 0} {os.write (buffer, 0, lane); }} Hold (java.io.IOException e) {Log.e ("TAG", e.getMessage ()); } Return os.toByteArray (); } @ Override Public Boolean On Crate Option Menu (menu menu) {getMenuInflater (). Flood (R.MenuMenuMmen, Menu); Back true; } Private class uploadPic AsyncTask and lt; SoapSerializationEnvelope, Zero, String & gt; {Secure string doInBackground (SoapSerializationEnvelope ... params) {string URL = "& lt; my web service"; String SOAP_ACTION = "http://tempuri.org/"; HTTP TranssextSE HTSE = New HTTP Transportation SE (URL); New Marshlabs 64 (). Register (Parame [0]); String responsems = ""; Try {htse.call (SOAP_ACTION + "Insert Image", Consulting [0]); Soap Affective Response = (Soap Experimental) Parameter [0] .getResponse (); ResponseMsg = response.toString (); } Hold (exception e) {responseMsg = e.getMessage (); } Return feedback message; }}
When I call the following Web method, the image is being uploaded to the SQL database
import system Web import system Web. Service import system system import System import system Data Scale client public square NWEmpPhotoHandler Implements System.Web.IHttpHandler public sub-process request (Reference HttpContext as) Implem father IHttpHandler.ProcessRequest dim ID string = context.Request.QueryString ( "ID") as dim con SqlConnection = New SqlConnection as (System.Configuration.ConfigurationManager.AppSettings ( "ConnectionString"). ToString ()) dim as SqlCommand = new cmd SqlCommand cmd.CommandType = CommandType.Text cmd.Parameters.AddWithValue ( "@ empid", ID) Con.Open () Dim dReader as SqlDataReader = cmd.ExecuteReader (, Thief "Choose picture where id = @empid") () dReader.Read () context.Respo nse.BinaryWrite (DirectCast (dReader ( "Photo"), get byte ())) dReader.Close () con.Close () End Sub ReadOnly property IsReusable () As Boolean Implements IHttpHandler.IsReusable < / P>
Where am I wrong
a) Uploading the image b) Save image c) Retrieving image
???
Please help me.
Thank you.
No comments:
Post a Comment