<info xmlns="http://myns.com">
<args>
<arg type="firstname">
<value>William</value>
</arg>
<arg type="lastname">
<value>Campbell</value>
</arg>
</info>
<info xmlns="http://myns.com"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<args>
<arg i:type="firstname">
<value>William</value>
</arg>
<arg i:type="lastname">
<value>Campbell</value>
</arg>
</info>
using System;
using System.ServiceModel;
using System.ServiceModel.Web;
[ServiceContract]
[DataContractFormat]
public interface IRPCService
{
[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/getuserxml?id={userID}")]
info GetUserXML(String userID);
}
http://www.experts-exchange.com/RPCService.svc/getuserxml?id=williamcampbell
using System;
using System.Runtime.Serialization;
[DataContract(Name="arg",
Namespace="http://myns.com")]
[KnownType(typeof(FirstNameArg))]
[KnownType(typeof(LastNameArg))]
public class BaseArg
{
public BaseArg() { }
[DataMember(Name="value")]
public String Value { get;set; }
}
[DataContract(Name="firstname",
Namespace="http://myns.com")]
public class FirstNameArg : BaseArg
{
}
[DataContract(Name="lastname",
Namespace="http://myns.com")]
public class LastNameArg : BaseArg
{
}
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
[DataContract(Name = "info",
Namespace = "http://myns.com")]
public class info
{
public info()
{
Args = new List<BaseArg>();
}
public void AddArg(BaseArg arg, String value)
{
arg.Value = value;
Args.Add(arg);
}
[DataMember(Name = "args")]
List<BaseArg> Args { get; set; }
}
<info>
</info>
<info>
<args>
</args>
</info>
<info>
<args>
<arg i:type="firstname">
</arg>
</args>
</info>
<info>
<args>
<arg i:type="firstname">
<value>William</value>
</arg>
</args>
</info>
public info GetUserXML(String userID)
{
// lookup userID in the Database
info exinfo = new info();
exinfo.AddArg(new FirstNameArg(), "William");
exinfo.AddArg(new LastNameArg(), "Campbell");
return exinfo;
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)