XML-RPC.NET Attributes

XML-RPC.NET uses Attributes to declare the XML-RPC properties of both Service and Proxy classes.

XmlRpcUrl Attribute

This attribute is used on an XML-RPC.NET Proxy class to specify the URI of the XML-RPC server to which the Proxy will connect. For example:

[XmlRpcUrl("http:/betty.userland.com/RPC2")]
class Betty : XmlRpcProxy
{
    ...
}

If this attribute is not defined on a proxy then the url can either be specified at design-time in Visual Studio:

or procedurally:

Betty betty = new Betty();
betty.Url =
"http:/betty.userland.com/RPC2";

XmlRpcMethod Attribute

This attribute is used both on Proxy and Service classes. In both cases it is used to specify that a method is being exposed as an XML-RPC method. For example:

[XmlRpcUrl("http:/betty.userland.com/RPC2")]
class Betty : XmlRpcProxy
{
    [XmlRpcMethod]
    public string getStateName(int stateNum)
    {
        ...
    }
}

When defining a Proxy class the name of the XML-RPC method may not be applicable as a .NET CLS class method, for example examples.getStateName, and so the XmlRpcMethod attribute can take a string value to specify the name of the XML-RPC method separately from the method name in the class. For example:

    [XmlRpcMethod("examples.getStateName"]
    public string GetStateName(int stateNum)
    {
        ...
    }

This also applies when defining a Service class - the method name to be exposed via XML-RPC can be specified in the XmlRpcMethod attribute where it is required to be different to the method name in the class.

When defining a Service a named attribute property - Description - may be optionally used to supply some descriptive text on the method. This text will then appear in the automatically generated documentation page for the Service. For example, the descriptive text supplied in the following definition will automatically appear in this page.

    [XmlRpcMethod("examples.getStateName",
                  Description="Return name of state given its number")]
    public string getStateName(int stateNum)
    {
        ...
    }

By default a method will appear in the automatically generated documentation page and results from introspection calls. This can be prevented by using the attribute property Hidden and setting it to true.

    [XmlRpcMethod(Hidden=true)]
    public string secretiveMethod(int stateNum)
    {
        ...
    }

XmlRpcService Attribute

This attribute enables descriptive text to be associated with the Service as a whole. The text is then displayed on the auto generated doc page for the Service.

[XmlRpcService("Implements similar methods to http:/betty.userland.com/RPC2")]
class BettyService : XmlRpcService
{
    [XmlRpcMethod]
    public string getStateName(int stateNum)
    {
        ...
    }
    ...

}

 


© Charles Cook, 2001 All Rights Reserved.
30 December 2001