Java Android应用程序无法访问WCF Rest服务

Java Android应用程序无法访问WCF Rest服务,java,c#,android,eclipse,wcf,Java,C#,Android,Eclipse,Wcf,我有一个使用eclipse编写的基本java android应用程序。我在一个设备上测试它,而不是在模拟器上(太慢)。MainActivity当前仅访问WCF url(代码如下)。WCF服务是一个简单的GET方法,托管在IIS上。我可以使用下面给出的url从firefox访问服务方法。我现在已经关闭了防火墙。在命令netstat-an上,我可以看到: TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 我的问题是,虽然可

我有一个使用eclipse编写的基本java android应用程序。我在一个设备上测试它,而不是在模拟器上(太慢)。MainActivity当前仅访问WCF url(代码如下)。WCF服务是一个简单的GET方法,托管在IIS上。我可以使用下面给出的url从firefox访问服务方法。我现在已经关闭了防火墙。在命令netstat-an上,我可以看到:

TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING
我的问题是,虽然可以从浏览器访问该服务,但我无法从应用程序连接。它一直在计时

我也尝试过localhost、10.0.2.2和我的局域网ip

我的代码是:

主要活动

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>
我已将其部署在IIS中的文件夹“tst”下

Web.config是:

<?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>
请查看代码,如果我犯了一些错误,请告诉我。后来我想用POST而不是GET

编辑::: 我已经通过浏览器调用调试了wcf。调试中似乎没有问题。我想在IIs上安装wcf时进行调试。我该怎么做??对WCF的调用也来自android应用程序。当来电时,fiddler没有显示任何新项目。如果有人使用此工具拦截来自android应用程序的请求,请帮助

编辑2::
已尝试更改wcf服务的端口。现在收到405的回复。请给出你的建议

需要更多信息吗?我可以使用我的局域网ip访问我的服务,也可以从浏览器“任何答案??请?识别问题的最简单方法是使用Fiddler检查您从Android应用程序到WCF服务的原始请求与浏览器请求。将尝试此操作并将结果发布到此处任何其他信息??我可以使用我的lan ip访问我的服务,也可以从浏览器访问“任何答案??请?确定问题的最简单方法是使用Fiddler检查您从Android应用程序到WCF服务的原始请求,而不是浏览器请求。我将尝试一下并在此处发布结果
<?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>
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);
}
}