I am creating WCF Restful service,I have followed
this link.
The service is created without any error, but when I am calling it from C#, its giving me error method not allowed.
What I have tried:
I tried using
[WebGet(UriTemplate = "GetData/")]
and
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetData/")]
but same error in both cases
This is how I am using in C#
DataContractJsonSerializer objseria = new DataContractJsonSerializer(typeof(string));
MemoryStream mem = new MemoryStream();
string data = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length);
WebClient webClient = new WebClient();
webClient.Headers["Content-type"] = "application/json";
webClient.Encoding = Encoding.UTF8;
webClient.UploadString("http://localhost:5025/MyService.svc/getdata/", "POST", data);
I tried changing the above code to this
WebClient proxy = new WebClient();
byte[] abc = proxy.DownloadData((new Uri("http://localhost:5025/Accounts.svc/getdata/")));
Stream strm = new MemoryStream(abc);
DataContractSerializer obj = new DataContractSerializer(typeof(string));
string result = obj.ReadObject(strm).ToString();
but I am getting below error in above code
"
There was an error deserializing the object of type System.String. The data at the root level is invalid. Line 1, position 1.
"
I am not getting any XML to check the error.