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

  • SEARCH
  • Home
  • 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 8967209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:11:32+00:00 2026-06-15T17:11:32+00:00

I read many tutorials but I could not get this running for my project.

  • 0

I read many tutorials but I could not get this running for my project. I made few GET services which send data and they work great, but I have problems receiving the data. I would really appreciate it if someone could tell me where I fail, instead of posting some links. 🙂
When I try to call the service in my browser I get the error: Method not allowed. But I Think this is just the first error.

Here is my code.
First the code in Android where I call the service:

public class MainActivity extends Activity {

String SERVICE_URI = "http://10.0.2.2:51602/RestServiceImpl.svc";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    HttpPost request = new HttpPost(SERVICE_URI + "/registerUser");
    request.setHeader("Accept", "application/json");
    request.setHeader("Content-type", "application/json");

    try {
        JSONStringer user = new JSONStringer()
                .object()
                .key("userInfo")
                .object()
                    .key("Email").value("mail")
                    .key("Password").value("pass")
                    .key("Cauntry").value("country")
                    .key("UserName").value("username")
                .endObject()
        .endObject();

        StringEntity entity = new StringEntity(user.toString());
        request.setEntity(entity);

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = httpClient.execute(request);


        } catch (JSONException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

IRestServiceImpl.cs:

[ServiceContract]
public interface IRestServiceImpl
{
    [OperationContract]
    [WebInvoke(Method = "POST",
        UriTemplate = "registerUser",
        BodyStyle = WebMessageBodyStyle.Wrapped,
        ResponseFormat = WebMessageFormat.Json,
        RequestFormat = WebMessageFormat.Json)]
    void receiveData(String data);
}

RestServiceImpl.cs:

public class RestServiceImpl : IRestServiceImpl
{
    public void receiveData(String data)
    {
        //some code
    }
}

Web.config:

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">

        <endpoint address ="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web">

        </endpoint>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>
  • 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-06-15T17:11:33+00:00Added an answer on June 15, 2026 at 5:11 pm

    Your problem is that you’re passing a JSON object to the operation, but the operation is expecting a JSON string. If I understand correctly the Java code, this is what you’re sending:

    {
        "userInfo" : {
            "Email" : "mail",
            "Password" : "pass",
            "Cauntry" : "country",
            "UserName" : "username"
        }
    }
    

    Which is not a JSON string.

    There are a couple of things you can do. The first alternative is to modify the operation not to take a string, but to take a data contract which is equivalent to that object.

    The code would look something like the one below. Notice that you should also change the body format to Bare (instead of Wrapped).

    public class RequestData
    {
        public UserInfo userInfo { get; set; }
    }
    
    public class UserInfo
    {
        public string Email { get; set; }
        public string Password { get; set; }
        public string Cauntry { get; set; } // typo to match the OP
        public string UserName { get; set; }
    }
    
    [ServiceContract]
    public interface IRestServiceImpl
    {
        [OperationContract]
        [WebInvoke(Method = "POST",
            UriTemplate = "registerUser",
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            RequestFormat = WebMessageFormat.Json)]
        void receiveData(RequestData data);
    }
    

    Another alternative, if the “schema” of the data changes every time, would be to take the input as a Stream (not a String). That way you should be able to accept basically any input. You may also need a content type mapper. You can find more information about this scenario at http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-receiving-arbitrary-data.aspx.

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

Sidebar

Related Questions

I've read many tutorials and made a search on the .net... but still I'm
I've read many answers here about this topic, but everyone suggests the BCP ||
I have read many questions about the facebook login but until not I didnt
I've read and watched many tutorials on NSUserDefaults in the iPhone OS/iOS SDK, but
I am using vbulletin 4.1.7 I've read many tutorials out there but none explais
I have read many questions and tutorials about this, I couldn't find a case
I've read many ODBC tutorials for C# on the net, and this code is
i HAVE read many Tutorials on posting to twitter using OAuth like here but
I read many threads in stackoverflow and also googled but i still have one
I read many posts about this problem like [this link][1] and one solution is

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.