.net - Android app won't return result from VB.NET WCF Service -
here wcf server code (vb.net)...
service1.svc
public class service1 implements iservice1 public sub new() end sub public function gettext() string implements iservice1.gettext return string.format("yo mtv rocks!") end function public function getdata(byval value integer) string implements iservice1.getdata return string.format("you entered: {0}", value) end function public function getdatausingdatacontract(byval composite compositetype) compositetype implements iservice1.getdatausingdatacontract if composite nothing throw new argumentnullexception("composite") end if if composite.boolvalue composite.stringvalue &= "suffix" end if return composite end function end class
iservice1.vb
' note: can use "rename" command on context menu change interface name "iservice1" in both code , config file together. <servicecontract()> public interface iservice1 <operationcontract()> _ <webget(uritemplate:="gettext", bodystyle:=webmessagebodystyle.wrappedrequest, responseformat:=webmessageformat.json, requestformat:=webmessageformat.json)> _ function gettext() string <operationcontract()> _ <webget(uritemplate:="getdata?v={value}", responseformat:=webmessageformat.json)> _ function getdata(byval value integer) string <operationcontract()> function getdatausingdatacontract(byval composite compositetype) compositetype ' todo: add service operations here end interface ' use data contract illustrated in sample below add composite types service operations. <datacontract()> public class compositetype <datamember()> public property boolvalue() boolean <datamember()> public property stringvalue() string
end class
web.config
<?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" strict="false" explicit="true" targetframework="4.0" /> <customerrors mode="off"/> </system.web> <system.servicemodel> <behaviors> <endpointbehaviors> <behavior name="httpbehavior"> <webhttp /> </behavior> </endpointbehaviors> <servicebehaviors> <behavior name=""> <servicemetadata httpgetenabled="true" /> <servicedebug includeexceptiondetailinfaults="false" /> </behavior> </servicebehaviors> </behaviors> <servicehostingenvironment multiplesitebindingsenabled="true" /> <services> <service name="httpwcfweb.vehicleservice"> <endpoint address="" behaviorconfiguration="httpbehavior" binding="webhttpbinding" contract="httpwcfweb.ivehicleservice" /> </service> </services> </system.servicemodel> <system.webserver> <modules runallmanagedmodulesforallrequests="true"/> </system.webserver> </configuration>
here android client code...
public static final string _url = "http://192.168.212.37:8080/service1.svc"; protected void login(){ try { // send request <service>/gettext httpget request = new httpget(_url + "/gettext"); request.setheader("accept", "application/json"); request.setheader("content-type", "application/json"); defaulthttpclient httpclient = new defaulthttpclient(); httpresponse response = httpclient.execute(request); httpentity responseentity = response.getentity(); // read response data buffer long intcount = responseentity.getcontentlength(); char[] buffer = new char[(int)responseentity.getcontentlength()]; inputstream stream = responseentity.getcontent(); inputstreamreader reader = new inputstreamreader(stream); reader.read(buffer); stream.close(); tvstatus.append("response: "); jsonarray plates = new jsonarray(new string(buffer)); (int = 0; < plates.length(); ++i) { tvstatus.append(plates.getstring(i)); } } catch (exception e) { e.printstacktrace(); } }
for unkown reason, can run vs 2010 client test , wcf host works fine. code above returns nothing (it's supposed return string)
any ideas on i'm doing wrong?
i'm not sure android (haven't done wcf stuff android yet) when access of our wcf services javascript have convert output of method json before sending javascript or else js nothing back.
i wonder if may case here? try returning formatted json object?
Comments
Post a Comment