Hello!
I have begun the conversion from Windows 8.1 to Universal apps for some off my application.I have noticed that MS does not support WCF soap on Windows Phone, and therefore i have converted mye Services to REST.
I have been successfull in implementing REST on a operationcontract with a reference type object, but i have not been successfull on the complex type operation.
WCF configuartion:
[WebInvoke(Method ="POST", UriTemplate = "/nySmerteEntitet/", RequestFormat =WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Wrapped)]
[OperationContract]
_02_DataClasser.SmerteEntitet nySmerteEntitet(_02_DataClasser.SmerteEntitet ent);
Client configuration:
var url = "http://" + valgtServer + "/ServiceIC.svc/nySmerteEntitet/";
var ent = new SmerteEntitet();
ent.BrukerId = DataModel.cStatic.Instance.BrukerId;
ent.Tidspunkt = DateTime.Now;
ent.YVerdi = verdi;
var jsonString = ServiceIC.Serialization.Serialize(ent);
HttpClient httpClient = new System.Net.Http.HttpClient();
HttpContent contentPost = new StringContent(jsonString, Encoding.UTF8, "application/json");
HttpResponseMessage response = await httpClient.PostAsync(url, contentPost);
if (!response.IsSuccessStatusCode)
throw new Exception("Error while maintaining entites");
string data = await response.Content.ReadAsStringAsync();
Server implenetation:
public _02_DataClasser.SmerteEntitet nySmerteEntitet(_02_DataClasser.SmerteEntitet ent)
{
if (ent == null)
throw new Exception("S: Entity was null");
var ta = new SmerterTableAdapter();
var dt = new dsIC.SmerterDataTable();
var dr = dt.NewSmerterRow();
dr.BrukerId = ent.BrukerId;
dr.Tidspunkt = ent.Tidspunkt;
dr.Verdi = ent.YVerdi;
ta.Update(dr);
return new _02_DataClasser.SmerteEntitet(dr);
}
When i try the code the server breaks on "throw new Exception("S: Entity was null");"
I have examined the client side and the json string seems legit.
I have seached the web for a solution and since this uses the WinRT namespace the PostAsJsonAsync does not exist on httpclient.
I would be very happy if i can get some information on how to solve this. Kind regards, Eirik