I have a requirement to create a simple HTTP C# restful web service hosted in IIS 7 that can support a POST from a callout and the format of the POST data does not seem to be handled properly. The requirement for the data member names is that they have a dash in them, such as custom-1. My problem is that the datamembers names who are custom-10 or higher are only giving me null for data. custom-1 thru custom-9 are fine.
If anyone can help, I appreciate it!!!
Here is the required format of the POST data:
<person-search-request xmlns="someurl">
<person>
<custom-1 />
<custom-2 />
<custom-3 />
<custom-4 />
<custom-5 />
<custom-6 />
<custom-7 />
<custom-8 />
<custom-9 />
<custom-10 />
<custom-11 />
<custom-12 />
<custom-13 />
<custom-14 />
<custom-15 />
<custom-16 />
<custom-17 />
<custom-18 />
<custom-19 />
<custom-20 />
</person>
</person-search-request>
My Web service data contract looks like this:
[CollectionDataContract(Name = "person-search-request", Namespace="")]
public class PersonsRequest : List<Person>
{ }
[CollectionDataContract(Name = "person-search-response", Namespace="")]
public class PersonsResponse : List<Person>
{ }
[DataContract(Name = "person", Namespace = "")]
public class Person
{
public Person()
{
Custom14 = String.Empty;
Custom13 = String.Empty;
Custom15 = String.Empty;
Custom16 = String.Empty;
Custom17 = String.Empty;
Custom18 = String.Empty;
Custom19 = String.Empty;
Custom20 = String.Empty;
Custom7 = String.Empty;
Custom8 = String.Empty;
Custom9 = String.Empty;
Custom1 = String.Empty;
Custom10 = String.Empty;
Custom11 = String.Empty;
Custom12 = String.Empty;
Custom3 = String.Empty;
Custom4 = String.Empty;
Custom5 = String.Empty;
Custom6 = String.Empty;
}
[DataMember(Name = "custom-14")]
public string Custom14 { get; set; }
[DataMember(Name = "custom-7")]
public string Custom7 { get; set; }
[DataMember(Name = "custom-8")]
public string Custom8 { get; set; }
[DataMember(Name = "custom-9")]
public string Custom9 { get; set; }
[DataMember(Name = "custom-13")]
public string Custom13 { get; set; }
[DataMember(Name = "custom-15")]
public string Custom15 { get; set; }
[DataMember(Name = "custom-16")]
public string Custom16 { get; set; }
[DataMember(Name = "custom-17")]
public string Custom17 { get; set; }
[DataMember(Name = "custom-18")]
public string Custom18 { get; set; }
[DataMember(Name = "custom-19")]
public string Custom19 { get; set; }
[DataMember(Name = "custom-20")]
public string Custom20 { get; set; }
[DataMember(Name = "custom-10")]
public string Custom10 { get; set; }
[DataMember(Name = "custom-11")]
public string Custom11 { get; set; }
[DataMember(Name = "custom-12")]
public string Custom12 { get; set; }
[DataMember(Name = "custom-1")]
public string Custom1 { get; set; }
[DataMember(Name = "custom-2")]
public string Custom2 { get; set; }
[DataMember(Name = "custom-3")]
public string Custom3 { get; set; }
[DataMember(Name = "custom-4")]
public string Custom4 { get; set; }
[DataMember(Name = "custom-5")]
public string Custom5 { get; set; }
[DataMember(Name = "custom-6")]
public string Custom6 { get; set; }
/// <summary>
}
My Service endpoint is setup like this:
[ServiceBehavior(IncludeExceptionDetailInFaults = true), AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed), ServiceContract]
public partial class Service
{
[WebHelp(Comment = "Person POST")]
[WebInvoke(UriTemplate = "person/v1.0/fetch", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)]
[OperationContract]
public PersonsResponse FetchPerson(PersonsRequest request)
{
....
}
}
The Post data looks like this (using Fiddler to test):
<person-search-request>
<person>
<custom-1>1</custom-1>
<custom-2>2</custom-2>
<custom-3>3</custom-3>
<custom-4>4</custom-4>
<custom-5>5</custom-5>
<custom-6>6</custom-6>
<custom-7>7</custom-7>
<custom-8>8</custom-8>
<custom-9>9</custom-9>
<custom-10>10</custom-10>
<custom-11>11</custom-11>
<custom-12>12</custom-12>
<custom-13>13</custom-13>
<custom-14>14</custom-14>
<custom-15 />
<custom-16 />
<custom-17 />
<custom-18 />
<custom-19 />
<custom-20 />
</person>
</person-search-request>
The data comes into the endpoint with nulls in the 10-20 custom tags. Anyone know why??? :(
This is what I see when I debug from the request object passed into the method.
Custom1 "1" string
Custom10 null string
Custom11 null string
Custom12 null string
Custom13 null string
Custom14 null string
Custom15 null string
Custom16 null string
Custom17 null string
Custom18 null string
Custom19 null string
Custom2 "2" string
Custom20 null string
Custom3 "3" string
Custom4 "4" string
Custom5 "5" string
Custom6 "6" string
Custom7 "7" string
Custom8 "8" string
Custom9 "9" string