Note that there are some explanatory texts on larger screens.

plurals
  1. POWebInvoke Parameter is NULL
    primarykey
    data
    text
    <p>I have a service where the operation contract looks like the following. I have a WebInvoke attribute and the method is set to POST. I do have a UriTemplate. The actual service method name is SaveUser. I am trying to pass in a User object (a data contract with properties annotated as data member attributes).</p> <pre><code>[OperationContract] [WebInvoke(Method = "POST", UriTemplate = "SaveUser", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json)] User SaveUser(User user); </code></pre> <p>The client looks like the following. For simplicity I have excluded the token and authorization etc.:</p> <pre><code>using (WebClient webClient = new WebClient()) { try { Random r = new Random(); var partitionKey = Guid.NewGuid().ToString(); var rowKey = r.Next(999900, 999999).ToString(); User u = new User() { UserId = partitionKey, FirstName = "First-" + DateTime.Now.Ticks.ToString(), LastName = "Last-" + DateTime.Now.Ticks.ToString(), LoginName = rowKey, Password = "password1", PayPalEmailAddress = "First" + DateTime.Now.Ticks.ToString() + "@verascend.com", PhoneNumber = "+1206" + r.Next(1234567, 9999999).ToString() }; string url = serviceBaseUrl + "/SaveUser"; webClient.Headers["Content-type"] = "application/json; charset=utf-8"; // webClient.Headers[HttpRequestHeader.Authorization] = authToken; DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(User)); using (var memStream = new MemoryStream()) { ser.WriteObject(memStream, u); Debug.WriteLine("-------------&gt; "+ByteArrayToString(memStream.ToArray())); webClient.UploadData(url, "POST", memStream.ToArray()); } } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError) { string responseText = string.Empty; using (Stream responseStream = ((HttpWebResponse)ex.Response).GetResponseStream()) { using (StreamReader streamReader = new StreamReader(responseStream)) { responseText = streamReader.ReadToEnd(); } } throw new Exception(responseText); } else { throw new Exception(ex.Message.ToString()); } } } </code></pre> <p><strong>Problem:</strong> The service method (actual service) is receiving the param (User) as NULL. What am I doing wrong? I tried adding the known type in the service contract but no luck.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload