After several days of learning and figuring out how to access the data without doing it the old fashion way. Here is what I have came up with:
Microsoft offers an XSD and SVCUTIL for converting xsd's to classes and making them serializable. The reason I was stuck on this project was because of the complex types, i've never done this before. I used:
Command Prompt: XSD.exe ServiceProviderTic.xsd /CLASSES
Which generated ServiceProviderTic.cs
I created a web service:
Interface:
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate="/MyService", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)]
XElement callRequestFunc(XElement request);
Class:
public XElement callRequestFunc(XElement request)
{
ServiceProviderTic requestSer = Utility.DeserializeData(request);
if (requestSer.Item.GetType() == typeof(RequestType))
{
RequestType reqObj = (RequestType)requestSer.Item;
string datapiece = reqObj.MsgType.ToString();
}
XElement responseSer = Utility.SerializeData(requestSer);
return responseSer;
}
}
XElement helped me accept plain old xml (POX) and respond with plain old xml. Below are the helper functions which serialize and deserialize my xelement. I also included extra code which removed namespaces I didn't need.
public class Utility
{
public static ServiceProviderTic DeserializeData(XElement request)
{
var ser = new XmlSerializer(typeof(ServiceProviderTic));
return (ServiceProviderTic)ser.Deserialize(request.CreateReader());
}
public static XElement SerializeData(ServiceProviderTic response)
{
using (var memoryStream = new MemoryStream())
{
using (TextWriter streamWriter = new StreamWriter(memoryStream))
{
var xmlSerializer = new XmlSerializer(typeof(ServiceProviderTic));
xmlSerializer.Serialize(streamWriter, response);
return Utility.RemoveAllNamespaces(XElement.Parse(Encoding.ASCII.GetString(memoryStream.ToArray())));
}
}
}
public static XElement RemoveAllNamespaces(XElement source)
{
return !source.HasElements
? new XElement(source.Name.LocalName)
{
Value = source.Value
}
: new XElement(source.Name.LocalName, source.Elements().Select(el => RemoveAllNamespaces(el)));
}
}
I hope this helps someone in the future!