find a location for property in a new city

Tuesday 4 January 2011

How to POST to REST WCF web services with Fiddler

After making a set of REST web services with WCF I tested them by making requests with a browser. This is fine for GET requests however you will need some HTTP building tool such as Fiddler to test a POST, PUT or DELETE REST web service.

To begin with I have a WCF REST web service that intends for a Comment object to be POSTed:
[WebInvoke(UriTemplate = "comment", Method = "POST",
  RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)]
public Comment Comment(Comment comment)
{
    return comment;
}

The definition of Comment is simple:
[DataContract(Namespace = "")]
public class Comment
{
    [DataMember]
    public string Body { get; set; }
}

Note this namespace is very important as it will need to be specified in the XML sent in the request. Personally I set my DataContract with no namespace to save having to write it out in the XML every time.

Now open up Fiddler and lets get testing:

Create a POST to your REST service in Fiddler

  1. Go to the Request Builder tab in Fiddler.
  2. Set the verb to POST
  3. Set the URL to the one of your service
  4. Type "Content-Type: application/xml" into the Request Headers. (This is the bit that got be stumped for hours)
  5. Add your XML to the Request Body like <Comment><Body>colin</Body></Comment>

If you did give your DataContract a namespace other than blank as I did you will need to specify it in the XML of your Request Body. Such as: <Comment xmlns="MyNameSpace"><Body>colin</Body></Comment>

Happy testing!

Follow britishdev on Twitter

70 comments:

  1. Thanks I did it . It works great

    ReplyDelete
  2. www.oniontest.org (EASY/SIMPLE) rest/http web service testing without mocking yourself to an imaginary world ! - Write an Onion !

    ReplyDelete
  3. That's a great way to test our services, really. I was struggling with all the work it takes to mock up my services until I found your post. Thank you so much!

    ReplyDelete
  4. Even If you have blank namespace you have to put
    xmlns="" in the request body ...

    http://pantestmb.blogspot.com/2011/10/pass-multiple-body-parameters-wcf-rest.html

    Whithout xmlns="" in the request body , problems can appear

    ReplyDelete
  5. Thanks for the tip but I'll be honest, I have never found any problems myself nor have the iPhone developers that consumed this API.

    What problems were you experiencing exactly? Just for my benefit in case I have missed something.

    ReplyDelete
  6. Hello, Thanks for the great tutorial. I tried to extend the class with inserting DateTime? variable in it as following:-

    [DataContract(Namespace = "")]
    public class Comment
    {
    [DataMember]
    public string BodyComment { get; set; }
    [DataMember]
    public DateTime? CreatedDate { get; set; }
    }

    And followed everything else as you mentioned in the tutorial.
    But when I'm sending a POST request like this:
    xyz, or
    xyz
    As I want CreatedDate to be empty, it is giving me "Http 400 Bad request error".

    Kindly suggest if I'm doing something wrong.

    ReplyDelete
    Replies
    1. Sorry POST didn't come, but it is like
      I'm sending xyz in body and empty CreatedDate...

      Delete
    2. Bit hard to debug this kind of thing remotely. Where is the exception being thrown and what is it when you are debugging?

      Delete
  7. Thank you so much. I have been trying to understand the WebInvoke attribute for a few days and your example made it clear.

    ReplyDelete
  8. Thank you so much, this is exactly what I was looking for.

    ReplyDelete
  9. Fantastic post, been knocking myself out working out why object was not posting correctly, the namespace did it.

    ReplyDelete
  10. Why is my Fiddler meets "415 Unsupported Media Type"?
    I do everything in your example...

    ReplyDelete
  11. This is a great inspiring article. I am pretty much pleased with your good work. You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.Contact Us Content

    ReplyDelete
  12. Thanks for sharing a very helpful AND ALSO very informative blogPromotion King

    ReplyDelete
  13. Online medium and audio visual media is undoubtedly the strongest medium these days with extensive reach to the audience.
    create your brand

    ReplyDelete
  14. With this, you ought to just trust your well deserved cash and speculation to an Ecommerce Web Development Company that brags a past filled with mastery and polished skill in the business.easy proven way to start a blog

    ReplyDelete
  15. However we do agree that there are a lot of differences in the way some of these web browsers operate and the various scripting and web coding languages they use and their interpretation of this.Kttp

    ReplyDelete
  16. In the event that you don't yet have a website, the initial step is to record precisely why you need a website and what you need it to improve the situation your business. hybrid app development

    ReplyDelete
  17. I suggest that you look around and see what the various web hosting companies have to offer before you make that final choice. www.ldainteractive.com

    ReplyDelete
  18. Hey, great post! I also interested in Fiddler and I think you might like this article - vue vs react

    ReplyDelete
  19. This is a front-end JavaScript library developed by Facebook. Most of the major applications are currently running on React.JS. The applications which required data changes constantly are using React.JS.

    ReplyDelete
  20. I found this as an informative and interesting post, so i think it is very useful and knowledgeable.- gta 5 cheats

    ReplyDelete
  21. great tutorial! Read also React vs Vue.js.Which to Choose?

    ReplyDelete
  22. This current Google's child should be in the best position of web structures.

    ReplyDelete
  23. Getting reliable SEO services has become a very tedious task now. Thank God that Canada's SEO Company is here to resolve our issues. Canada's SEO Company

    ReplyDelete
  24. You ought to be a part of a contest for one of the finest sites on the internet. I will recommend this web site!
    fnaf world download

    ReplyDelete
  25. Web development is a specialized area of work which involves an understanding of the web development technologies and all other related processes. Web developers do not automatically produce a fine website on demand. small business web design Toronto

    ReplyDelete
  26. This comment has been removed by the author.

    ReplyDelete
  27. It is an excellent blog, I have ever seen. I found all the material on this blog utmost unique and well written. And, I have decided to visit it again and again. animal logo design

    ReplyDelete
  28. Very informative post! There is a lot of information here that can help any business get started with a successful social networking campaign. Webdesign

    ReplyDelete
  29. Thanks for sharing the post.. parents are worlds best person in each lives of individual..they need or must succeed to sustain needs of the family. Webdesign

    ReplyDelete
  30. I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing. Webdesign

    ReplyDelete
  31. Webdesigner waar u een professionele en betaalbare website kan laten maken? De nr. 1 webdesigner in Limburg, Antwerpen en Vlaams-Brabant voor SEO websites. Webdesigner

    ReplyDelete
  32. The challenge on independent occupation sheets is wild. How is somebody with no portfolio expected to emerge? Webdesign

    ReplyDelete
  33. I have read your blog it is very helpful for me. I want to say thanks to you. I have bookmark your site for future updates. Webdesign bureau

    ReplyDelete
  34. Here are just a few of the very important web design and search engine optimization (SEO) elements seo services in gurugram haryana that website builders can't do for you:

    ReplyDelete
  35. I would like to say that this blog really convinced me to do it! Thanks, very good post. dominio y página web

    ReplyDelete
  36. There are a lot more online business stages like shopify, virtuemart, zeuscart, zencart and so on. Picking any of these awesome stages guarantees your website executes as required.
    web developer nuneaton

    ReplyDelete
  37. I am very happy to discover your post as it will become on top in my collection of favorite blogs to visit. freelance web designer

    ReplyDelete
  38. My webpage has a few hints on the best way to perform site design improvement (additionally know as SEO) on your site. Webdesign

    ReplyDelete
  39. This succession, whenever rehashed by different organizations, prompts a gathering of insufficiently planned sites. premium wordpress blog themes

    ReplyDelete
  40. I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. theymakedesign

    ReplyDelete
  41. Thanks for posting such an excellent read, i have bookmarked your site and will post it to my followers Web Designers Toronto

    ReplyDelete
  42. I love the way you write and share your niche! Very interesting and different! Keep it coming! design

    ReplyDelete
  43. They are over-burden with work and frequently, you won't think about them since they don't have time (or need) to showcase themselves. Webdesign

    ReplyDelete
  44. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. https://www.seoragno.com

    ReplyDelete
  45. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! jasa pengiriman barang ke indonesia dari china

    ReplyDelete
  46. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. business setup dubai

    ReplyDelete
  47. Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking. corner bathroom sink

    ReplyDelete
  48. We all stand in awe at the genius behind simple strap lines that have the ability to recall entire branding messages.smm panel

    ReplyDelete
  49. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. forsage review

    ReplyDelete
  50. Making an online presence could help you whether you sell things on the web or need to utilize the web to drive individuals to your neighborhood business. Professional graphic design

    ReplyDelete
  51. Choosing to begin a vocation in Website composition is the initial segment. The focal points are engaging. Webdesign

    ReplyDelete
  52. Site improvement specialists apply the freshest examination administration, which positively affects a site. SEO organizations are confronting incredible rivalry in the SEO field. Website laten maken

    ReplyDelete
  53. Thank you for taking the time to publish this information very useful! SDWAN

    ReplyDelete
  54. 55% of the current SEOs in the market discover third party referencing to be the most monotonous and tedious work. Webdesign-seo-antwerpen.be

    ReplyDelete
  55. It's the Ecommerce website design in USA that really can facilitate you to make the most of the internet based company techniques and process as well as it can permit you to conduct the internet based company in the most systematic method. https://www.sandeepmehta.co.in/affordable-seo-services-delhi/

    ReplyDelete
  56. buy electronics online in Pakistan at best prices delivered at your doorstep. Get free shipping.

    ReplyDelete
  57. For the advancement of your firm, then, at that point you can generally trust the web designers.
    https://onohosting.com/

    ReplyDelete
  58. Making your web webpage can be an interesting interaction. Picking the best web design firm for your business web webpage is a vital choice.MavericksMedia

    ReplyDelete
  59. The categorisation is huge and so are the possibilities to get into it. You will need to use for the U.S. Civil offerings examinations to get a job within the Indian Administrative Service, Indian Police Service, Indian Foreign Service, and other comparable designations. It’s one of the maximum sought of Fresher jobs in India and calls in for lots of efforts to clear the exam. The pay may be 12 lakhs and

    tn govt jobs

    ReplyDelete
  60. I can set up my new idea from this post. It gives in depth information. Thanks for this valuable information for all,.. Web Design Melbourne

    ReplyDelete
  61. Multilingua is the best foreign language institute in Delhi that offers the best in-its-class language Education, IELTS training & personalized guidance to students who wish to learn and are willing to try new and unfamiliar things. We are also one of the BEST language & IELTS coaching, IELTS Training Course, English Language Course, German Language Course, French Language Institute, Chinese Language Classes in Delhi, Language Translation services, provide training to a large number of students every year who are looking to work & study Abroad.

    ReplyDelete
  62. Multilingua is the best foreign language institute in Delhi that offers the best in-its-class language Education, IELTS training &personalized guidance to students who wish to learn and are willing totry new and unfamiliar things. We are also one of the BEST language &
    IELTS coaching, IELTS Training Course, English Language Course, GermanLanguage Course, French Language Institute, Chinese Language Classesin Delhi, Language Translation services, provide training to a largenumber of students every year who are looking to work & study Abroad.

    ReplyDelete
  63. In order to improve the platform, we hope that current cryptocurrency users will sign up after logging in to Crypto.com . And you may visit the crypto.com website to find out more information if you're still interested.
    The quicker and safer option for sending and receiving money online is through PayPal. Initiate or establish a merchant account in order to receive payments.The quicker and safer option for sending and receiving money online is through Paypal Login . Initiate or establish a merchant account in order to receive payments.
    A peer-to-peer (P2P) payment app, Cash App allows users to transfer, receive, and invest money. We want to be clear that Cash App Login is not a bank, but rather a financial platform. With the assistance of its financial partners, it offers its users banking services.

    ReplyDelete