Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6811963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:23:32+00:00 2026-05-26T20:23:32+00:00

I have the following code in a WCF Service that returns a string, and

  • 0

I have the following code in a WCF Service that returns a string, and I’m trying to consume it in an Android app.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace HelloService
{
    public class HelloService : IHelloService
    {
        public string SayHello()
        {
            return "Bonjuor Android from WCF Service";
        }
    }
}

I have two problems,

1, I have no idea if I’m even close with the Java due to the try catch blocks. If I have them in the code the app works but doesn’t display the text in the toast or text view, and if I leave the try catch blocks out Eclipse tell me to fix the problem, add a try catch block…lol.

And 2, I have no idea what I’m doing.

@Override
public void onCreate(Bundle icicle)
{
    super.onCreate(icicle);
    setContentView(R.layout.contacts);               

try 
{

        DefaultHttpClient httpClient = new DefaultHttpClient();
        URI uri = new URI("http://www.themorningtonpeninsula.com/HelloService/HelloService.svc"); 

        HttpGet httpget = new HttpGet(uri + "/SayHello");
        httpget.setHeader("Accept", "application/json");
        httpget.setHeader("Content-type", "application/json; charset=utf-8");

        HttpResponse response = httpClient.execute(httpget);
        HttpEntity responseEntity = response.getEntity();

        long intCount = responseEntity.getContentLength();

        char[] buffer = new char[(int)intCount];
        InputStream stream = responseEntity.getContent();
        InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
        try
        {
                reader.read(buffer);
                String str = new String(buffer);
                TextView thetext = new TextView(this);
                thetext.setText(str);
                setContentView(thetext);
                Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
            }

            catch (IOException e) 
            {
                e.printStackTrace();
            }
            stream.close();

        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }
    } 
}

Can someone please have a look at the code and let me know if I’m even close, or even better point me too, or post some code that does work???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:23:33+00:00Added an answer on May 26, 2026 at 8:23 pm

    All fixed, the Java code works fine, the problem was my WCF Service needed work. It wasn’t passing back correctly formatted JSON objects. So I went back and and found a great tutorial simple and to the point. I must have completed 10 tutorials before finding this one. Pat on the back for the author.

    http://www.codeproject.com/KB/WCF/RestServiceAPI.aspx

    Cheers,

    Mike.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using WCF RIA Services and I have a domain service method that returns
Background information: I have the following code in a WCF service. GetDataTable returns a
I have the following code in WCF service to throw a custom fault based
Let's say that I have specified the following WCF REST Service at the address
I have a WCF service that calls the following method in one of my
I have the following code where SprintServiceClient is a reference to a WCF Service-
I have a silverlight app that talks to a WCF service inside of an
I now have the following code, which calls a WCF service, it get some
I have the follwing code that provides an auto refresh feature to a WCF
I have the following XML Parsing code in my application: public static XElement Parse(string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.