Java Android未连接到在浏览器中工作的WCF服务

Java Android未连接到在浏览器中工作的WCF服务,java,c#,android,web-services,wcf,Java,C#,Android,Web Services,Wcf,我有一个WCF服务(在浏览器中尝试了它)它的代码 [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Login/?username={username}&password={password}")] bool Login(string us

我有一个WCF服务(在浏览器中尝试了它)它的代码

[OperationContract]
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Login/?username={username}&password={password}")]
    bool Login(string username, string password);

    [OperationContract]
    [WebGet(UriTemplate = "Search/?query={query}&type={type}", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
    List<AndroidBook> Search(string query, int type);
这是正确的,但在尝试使用以下代码连接android客户端时:

try {
                        HttpClient httpclient = new DefaultHttpClient();
                        HttpResponse response = httpclient.execute(new HttpGet(urls));
                        StatusLine statusLine = response.getStatusLine();
                        if(statusLine.getStatusCode() == HttpStatus.SC_OK){
                            ByteArrayOutputStream out = new ByteArrayOutputStream();
                            response.getEntity().writeTo(out);
                            out.close();
                            String responseString = out.toString();
                            //..more logic
                        } else{
                            //Closes the connection.
                            response.getEntity().getContent().close();
                            throw new IOException(statusLine.getReasonPhrase());
                        }
                    } catch (IOException e) {
                        Log.e("HTTP GET:", e.toString());
                    }
我遇到了
filenotfound
的异常,或者当我收到外部代码的响应时,我收到了一个
错误的请求
,我在谷歌上搜索了这个问题,遇到了同样的问题,并阅读了以下文章



使用fiddler,我在JSON中得到了正确的响应
任何帮助都将不胜感激:)

您是否在android中使用了asynctask或用于网络操作的线程?@IllegalArgument我读到了关于
asynctask
,但出于测试目的,我在android代码
StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build()中添加了以下内容:;StrictMode.setThreadPolicy(策略){"LoginResult":true}
try {
                        HttpClient httpclient = new DefaultHttpClient();
                        HttpResponse response = httpclient.execute(new HttpGet(urls));
                        StatusLine statusLine = response.getStatusLine();
                        if(statusLine.getStatusCode() == HttpStatus.SC_OK){
                            ByteArrayOutputStream out = new ByteArrayOutputStream();
                            response.getEntity().writeTo(out);
                            out.close();
                            String responseString = out.toString();
                            //..more logic
                        } else{
                            //Closes the connection.
                            response.getEntity().getContent().close();
                            throw new IOException(statusLine.getReasonPhrase());
                        }
                    } catch (IOException e) {
                        Log.e("HTTP GET:", e.toString());
                    }