I have a rudimentary java android app written using eclipse. I am testing it on a device rather than the emulator (too slow). The MainActivity is currently only accessing a WCF url(code below). The WCF service is a simple GET method which is hosted on IIS. I can access the service method from firefox with the url given below. I have turned off the firewall for now. and on the command netstat -an I can see :
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING
My problem is that though the service is accessible from the browser, I am unable to connect from the app. It keeps timing out.
I have tried localhost, 10.0.2.2 andd my lan ip as well.
My code is:
MainActivity
URL url = new URL("http://10.0.2.2:8080/tst/Service1.svc/getMsg/kkk");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setRequestMethod("GET");
urlConnection.setUseCaches(false);
urlConnection.setConnectTimeout(10000);
urlConnection.setReadTimeout(10000);
urlConnection.setRequestProperty("Content-Type","application/json");
urlConnection.setRequestProperty("Host", "10.0.2.2:8080");
urlConnection.connect();
int HttpResult =urlConnection.getResponseCode();
if(HttpResult ==HttpURLConnection.HTTP_OK)
{
....
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.secondprj"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="23" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Service code is
public class Service1 : IService1
{
public string GetMessage(String name)
{
return "abc " + name;
}
...
I have deployed it under folder 'tst' in IIS.
The Web.config is:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<service
name="WcfService1.Service1"
>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/"/>
</baseAddresses>
</host>
<endpoint address=""
binding="webHttpBinding"
contract="WcfService1.IService1"
behaviorConfiguration="web"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web" >
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
Interface
namespace WcfService1
{
[ServiceContract]
public interface IService1
{
[OperationContract]
//[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json,
// ResponseFormat = WebMessageFormat.Json,
//UriTemplate = "getMsg")]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "getMsg/{name}")]
string GetMessage(string name);
}
}
Please look in to the code and let me know if I have made some mistake. Later I want to use POST rather than the GET
EDIT::: I have debugged the wcf using a call from the browser. There seems to be no problem in the debugging. I want to debug when the wcf is installed on IIs. How would i do that?? Also the call to the WCF comes from the android app. When the call comes fiddler did not show any new item. If any one has used this tool for intercepting requests from an android app please help...
EDIT2:: Tried changing the port of the wcf service. Now getting a 405 response. Please give your suggestions!