Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple WCF service, not all parameters from client making through to the service
    primarykey
    data
    text
    <p>I wasn't exactly sure how to ask this so I made an <a href="http://sscce.org/" rel="nofollow noreferrer">SSCCE</a></p> <p>I have this simple WCF service</p> <pre><code>[ServiceContract] [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] public class EmailService { [WebInvoke(UriTemplate = "/SendEmail", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Xml)] public bool SendEmail(EmailData data) { try { byte[] fileBinaryContents = Convert.FromBase64String(data.Enc64FileContents); File.WriteAllBytes(data.FileName, fileBinaryContents); return true; } catch (Exception) { return false; } } } [DataContract(Namespace = "http://somenamespace/")] public class EmailData { [DataMember] public string FileName { get; set; } [DataMember] public string EmailAddress { get; set; } [DataMember] public string Enc64FileContents { get; set; } } </code></pre> <p>and I'm trying to get a Winforms client to call the webservice method; this is what I have</p> <pre><code>string URI = " http://localhost:59961/EmailService/SendEmail"; string fileContents = Convert.ToBase64String(File.ReadAllBytes("test.txt")); EmailData emailData = new EmailData { EmailAddress = "foo@bar.com", Enc64FileContents = fileContents, FileName = "test.txt" }; XNamespace ns = "http://somenamespace/"; XElement emailDataElement = new XElement(ns + "EmailData"); emailDataElement.Add(new XElement(ns + "FileName", emailData.FileName)); emailDataElement.Add(new XElement(ns + "Enc64FileContents", emailData.Enc64FileContents)); emailDataElement.Add(new XElement(ns + "EmailAddress", emailData.EmailAddress)); var xml = emailDataElement.ToString(SaveOptions.DisableFormatting); using (WebClient wc = new WebClient()) { wc.Headers[HttpRequestHeader.ContentType] = "application/xml; charset=utf-8"; string response = wc.UploadString(URI, "POST", xml); } </code></pre> <p>now on the service side, some of the properties are null as shown by the following screenshot. <img src="https://i.stack.imgur.com/m63hX.png" alt="enter image description here"></p> <p>Why is it that the <code>FileName</code> has the right value but the others don't ?</p>
    singulars
    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.
    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