You can not use POST with GET. If you wish to use POST, then you have to use either client or server side code. Also testing it with WCFTestClient.exe will help you.
Please "Mark As Answer" if the post helped you.
mitja.gti | www.mitjagti.com
I just created a new service using the "WCF REST Service Template 40(CS) " extension.
I did not change ANY code in it at all. All i did was put a break point in the GetCollection(), and Create(SampleItem instance) function.
These are called from a get and a post.
I then ran the project
It came up in the browser, i then copied the url to restclient ( a firefox extension) and sent a get message to the url (http://localhost:56686/service1/)
It returned data, i then ran the help for the post function. and copied the xml request and pasted it into the restclient body. set it to post and sent it - bad request. Just to test i also ran the json data as well with the same result.
WCF services are complicated for beginners and one must have advanced knowledge of various standards, protocols, ... to even start working with them and knowing how to debug an application is essential.
I'm not familliar with a Firefox extension you are using. One should know that by default WCF method accepts ONLY XML unless you set it to Json (then it accepts ONLY JSON).
If you'll write the client in C# (server side) then you must add a service reference and when you browse to
http://localhost:port/service1/ with metadata enabled you should see an example page of how to create a client.
If you will write the client in jQuery or Javascript then you have an example in my previous post/link.
I'm not sure what XML or Json you are posting and where you got them but without relavant code samples of your application or a debug log it's impossible to suggest a solution.
lewval3
0 Points
2 Posts
WCF Rest Service Template fails
Jul 28, 2012 08:23 PM|LINK
I have been having issues trying to get a rest service going, so I decided to generate a simple service to make sure everything was good.
I generated a new wcd service app use the template.
The only thing i have changed in the code is to remove the exceptions with
return new SampleItem();
and the WebInvoke to
[WebInvoke(UriTemplate = "", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
the get works fine, the post will not work!
I am using the sample body from the help page
{ "Id":2147483647, "StringValue":"String content" }
to this address http://localhost:53134/Service1/
But i get a bad request
Any suggestions?
mitja.GTI
Star
11157 Points
2094 Posts
Re: WCF Rest Service Template fails
Jul 29, 2012 09:11 AM|LINK
Hi lewval3
please take a look at this thread and my last post in it.
You can not use POST with GET. If you wish to use POST, then you have to use either client or server side code. Also testing it with WCFTestClient.exe will help you.
mitja.gti | www.mitjagti.com
lewval3
0 Points
2 Posts
Re: WCF Rest Service Template fails
Jul 29, 2012 01:52 PM|LINK
I don't understand.
I just created a new service using the "WCF REST Service Template 40(CS) " extension.
I did not change ANY code in it at all. All i did was put a break point in the GetCollection(), and Create(SampleItem instance) function.
These are called from a get and a post.
I then ran the project
It came up in the browser, i then copied the url to restclient ( a firefox extension) and sent a get message to the url (http://localhost:56686/service1/)
It returned data, i then ran the help for the post function. and copied the xml request and pasted it into the restclient body. set it to post and sent it - bad request. Just to test i also ran the json data as well with the same result.
mitja.GTI
Star
11157 Points
2094 Posts
Re: WCF Rest Service Template fails
Jul 29, 2012 03:37 PM|LINK
Hi lewval3
WCF services are complicated for beginners and one must have advanced knowledge of various standards, protocols, ... to even start working with them and knowing how to debug an application is essential.
I'm not familliar with a Firefox extension you are using. One should know that by default WCF method accepts ONLY XML unless you set it to Json (then it accepts ONLY JSON).
If you'll write the client in C# (server side) then you must add a service reference and when you browse to http://localhost:port/service1/ with metadata enabled you should see an example page of how to create a client.
If you will write the client in jQuery or Javascript then you have an example in my previous post/link.
I'm not sure what XML or Json you are posting and where you got them but without relavant code samples of your application or a debug log it's impossible to suggest a solution.
I really suggest you start learing from the beggining... Here's a Beginner's Guide to Windows Communication Foundation.
mitja.gti | www.mitjagti.com