Click here to Skip to main content
15,881,870 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
C#
[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:
C#
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:
C#
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
Posted

1 solution

Just found it.

C#
[WebInvoke(Method ="POST", UriTemplate = "/nySmerteEntitet/", RequestFormat =WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Bare)]
     [OperationContract]
     _02_DataClasser.SmerteEntitet nySmerteEntitet(_02_DataClasser.SmerteEntitet ent);


Changed the BodyStyle to Bare.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900