I call web service WCF by php curl
iservice.cs
{
[OperationContract]
[WebInvoke(UriTemplate = "/SaveData",Method = "*",BodyStyle = WebMessageBodyStyle.ق , ResponseFormat = WebMessageFormat.Json,RequestFormat =WebMessageFormat.Json)]
string SaveData(String DataResult);
}
service.cs
public class Service : IService
{
public string SaveData(String DataResult)
{
return "OK";
}
}
when i post json by this code
CURLOPT_POSTFIELDS => "\r\n\"{results:[{msgId:'1005',to:'966001',status:'D'},{msgId:'1005',to:'966002',status:'D'}]}\"",
return "OK"
But when i post json by this code
CURLOPT_POSTFIELDS => "{results:[{msgId:'1005',to:'966001',status:'D'},{msgId:'1005',to:'966002',status:'D'}]}",
return error :
The server encountered an error processing the request. The exception message is 'There was an error checking start element of object of type JsonData. The token '"' was expected but found 'r'.'. See server logs for more details. The exception stack trace is:
Difference between them "\r\n\"
The problem is String variable not accepting json encoding.
I want to solve in Iservice.cs because the json is post by a company and can not be changed it
How to modify the String DataResult to receive the posting json
What I have tried:
I change the string with this
string SaveData(RootObject DataResult);
}
[DataContract]
public class JsonData
{
[DataMember]
public string msgId { get; set; }
[DataMember]
public string to { get; set; }
[DataMember]
public string status { get; set; }
}
[DataContract]
public class RootObject
{
[DataMember]
public List<JsonData> results { get; set; }
}