How do I upload a file from an android device to a restful wcf service? -


i'm building android app , need upload photo taken camera. need upload restful wcf service. have looked @ many tutorials can't seem working. think problem lies wcf service. not exceptions response 400 bad request. since wcf service running on localhost, using 10.0.2.2 access android emulator. able call other service methods on local service 1 fails.

java

httppost httppost = new httppost("http://10.0.2.2:53943/imageservice/uploadinspectionphoto"); file photo = new file(environment.getexternalstoragedirectory(), "01.jpg"); multipartentity t = new multipartentity(); t.addpart("t", new filebody(photo)); //t.addpart(new formbodypart("t", new filebody(photo))); tired httppost.setentity(t); httpresponse response = httpclient.execute(httppost); 

wcf

[servicecontract] [aspnetcompatibilityrequirements(requirementsmode = aspnetcompatibilityrequirementsmode.allowed)] [servicebehavior(instancecontextmode = instancecontextmode.percall)] public class imageservice {         [webinvoke(method = "post")]         public void uploadinspectionphoto(stream t)         {             // put breakpoint here never gets here             // stream         } } 

config file

<?xml version="1.0"?> <configuration>    <system.web>     <compilation debug="true" targetframework="4.0" />       <customerrors mode="off"></customerrors>   </system.web>    <system.webserver>     <modules runallmanagedmodulesforallrequests="true">       <add name="urlroutingmodule" type="system.web.routing.urlroutingmodule, system.web, version=4.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a" />     </modules>   </system.webserver>    <system.servicemodel>     <servicehostingenvironment aspnetcompatibilityenabled="true"/>       <bindings>           <!--<basichttpbinding>               <binding name="basichttpstreaming" transfermode="streamed">               </binding>           </basichttpbinding>-->           <webhttpbinding>               <binding name="webhttpdtreaming" transfermode="streamed" >               </binding>           </webhttpbinding>       </bindings>     <standardendpoints>       <webhttpendpoint>         <!--              configure wcf rest service base address via global.asax.cs file , default endpoint              via attributes on <standardendpoint> element below         -->         <standardendpoint name="" helpenabled="true" automaticformatselectionenabled="true" />       </webhttpendpoint>     </standardendpoints>       <services>           <service behaviorconfiguration="publishmetadatabehavior" name="systemdesign.collaborate.services.imageservice">               <endpoint address="soap" binding="basichttpbinding" name="soap" contract="systemdesign.collaborate.services.imageservice"/>               <endpoint address="mex" binding="mexhttpbinding" name="mex" contract="imetadataexchange" />           </service>       </services>       <behaviors>           <servicebehaviors>               <behavior name="publishmetadatabehavior">                   <servicemetadata httpgetenabled="true" policyversion="policy15"/>               </behavior>           </servicebehaviors>       </behaviors>   </system.servicemodel>  </configuration> 

what doing wrong?

is using webhttpbinding raw programming model on service side option you? see these two blog posts detailed step-by-step instructions on how pull off.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -