Following is the sample function to configure firewall rule in VCloud API 5.1 for C#.
/// <summary>
/// To create a Firewall rule type object. This object is used to configure firewall.
/// </summary>
/// <param name="name">Rule name</param>
/// <param name="sourceIpRange">Source IP Range</param>
/// <param name="protocols">Firewall Type Protocols</param>
/// <param name="action">Firewall policy type</param>
/// <param name="sourcePort">Source port</param>
/// <param name="destinationIpRange">Destiniation Ip address range.</param>
/// <param name="destinationPort">Destination</param>
/// <param name="isEnabled">Enable/Disable rule</param>
/// <param name="enableLogging">Enable/Disable logging.</param>
/// <returns>Firewall Rule</returns>
public static FirewallRuleType CreateFirewallRule(string name, string sourceIpRange, FirewallRuleTypeProtocols protocols, FirewallPolicyType action, int sourcePort, string destinationIpRange, int destinationPort, bool isEnabled, bool enableLogging)
{
//Create firewall rule type object.
FirewallRuleType firewallRuleType = new FirewallRuleType();
//Configure isEnable parameter from UI enabled checkbox.
firewallRuleType.IsEnabled = isEnabled;
firewallRuleType.IsEnabledSpecified = true;
//Set Rule description from UI Name textbox.
firewallRuleType.Description = name;
//Normally it is a port number.
firewallRuleType.SourcePortRange = sourcePort.ToString();
firewallRuleType.SourcePortSpecified = true;
//Configure Protocol
var protocol = new FirewallRuleTypeProtocols();
//Set protocol object value
protocol.Items = new object[] { true };
//Set Element name
protocol.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.Tcp };
//Set Protocol
firewallRuleType.Protocols = protocol;
//Set destination IP range
firewallRuleType.Item = destinationIpRange;
//Normally it is port number.
firewallRuleType.DestinationPortRange = destinationPort.ToString();
//Set Source Ip range
firewallRuleType.Item1 = sourceIpRange;
//Configure Enable logging from UI logging checkbox.
firewallRuleType.EnableLogging = enableLogging;
firewallRuleType.EnableLoggingSpecified = true;
//Configue default action allow/deny.
firewallRuleType.Policy = action.Value();
return firewallRuleType;
}