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 8028499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:09:16+00:00 2026-06-05T00:09:16+00:00

i have a RESTful WCF service and one of its methods use an Object

  • 0

i have a RESTful WCF service and one of its methods use an Object as parameter

[WebInvoke(UriTemplate = "save", Method = "POST", RequestFormat = WebMessageFormat.Xml, ResponseFormat= WebMessageFormat.Xml), OperationContract]
        public SampleItem Create(SampleItem instance)
        {
            return new SampleItem() { Id = 1, StringValue = "saved" };
            // TODO: Add the new instance of SampleItem to the collection
            //throw new NotImplementedException();
        }

I am trying to call this method from my eclipse android project. i am using these lines of codes

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost post=new HttpPost("http://10.0.2.2:2768/Service1.svc/save");
ArrayList<NameValuePair> nvp= new ArrayList<NameValuePair>();

nvp.add(new BasicNameValuePair("Id", "1"));
nvp.add(new BasicNameValuePair("StringValue", "yolo"));

post.setEntity(new UrlEncodedFormEntity(nvp));
HttpResponse httpResponse = httpClient.execute(post);
HttpEntity httpEntity = httpResponse.getEntity();
String xml = EntityUtils.toString(httpEntity);

Every time i get this error Method not allowed. in the XML that is returned by the service method.

i have tried invoking it from the browser, but encountered the same error there.

please tell me what i am doing wrong and what i can do instead.

thanks in advance to anyone who can help.

note: other methods which do not use object as parameter are working fine.

EDIT: tried Fiddler2 with success. but stalled again.

i have tried invoking the method SampleItem Create(SampleItem instance) with the url http://localhost:2768/Service1.svc/save and it works. the method returns the object in XML format.

in fiddler i added the request body as
<SampleItem xmlns="http://schemas.datacontract.org/2004/07/WcfRestService1" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Id>1</Id><StringValue>saved</StringValue></SampleItem>

but the problem is that i can not find any way to add this xml string to the HttpPost or HttpRequest as the requestbody eclipse android project.

note: passing the xml string as Header or UrlEncodedFormEntity did not 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-06-05T00:09:18+00:00Added an answer on June 5, 2026 at 12:09 am

    First, you should get the Web Service method working from the browser – I recommend using Fiddler2 – its easier to construct the request body with your object and also to set the request headers when doing a post. It will show you the response so should help with debugging.
    As for your code, I’m doing a POST to a WCF service and instead of doing

    post.setEntity(new UrlEncodedFormEntity(nvp));
    

    I’m simply doing:

    HttpPost request = new HttpPost(url);
    
    // Add headers.
    for(NameValuePair h : headers)
    {
         request.addHeader(h.getName(), h.getValue());
    }
    

    (I am using JSONObjects and I have RequestFormat = WebMessageFormat.Json in my WebInvoke parameters.

    Also, check your using the correct UriTemplate name in your url as they are case sensitive.

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

Sidebar

Related Questions

I have a RESTful WCF service that exposes a method that takes in an
I have a RESTful WCF application that makes use of custom classes as service
I have a RESTful WCF service with a method declared like this: [OperationContract(Name =
I have a RESTful WCF service that has an upload method accepting more than
I'm working with a RESTful WCF service. One of the service methods returns byte[]
I have a very simple (new to this) RESTful WCF service that uses a
We have created a WCF RESTful service for a WPF(UI) Application. The UI sends
I have a RESTful service that, when I try to save a new record
I have a WCF service with multiple operations exposed as a RESTful API. Most
I have to secure a WCF RESTful service i'm thinking of doing it in

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.