Creating Proxies
This page describes all the ways an application can create a proxy.
Creating a Proxy from a String
The constructor of the generated proxy class allows you to construct a proxy from a communicator and a stringified representation of the proxy, as shown in the following example:
greeter = GreeterPrx(communicator, "greeter:tcp -h localhost -p 4061")
Creating a Proxy from a Property
Rather than hard-coding a stringified proxy as the previous example demonstrated, an application can gain more flexibility by externalizing the proxy in a configuration property. For example, we can define a property that contains our stringified proxy as follows:
Greeter.Proxy=greeter:tcp -h localhost -p 4051
We can use the propertyToProxy
method on Communicator
to convert the property's value into a proxy. A null proxy is returned if no property is found with the specified name.
greeterObj = communicator.propertyToProxy("Greeter.Proxy")
As an added convenience, propertyToProxy
allows you to define subordinate properties that configure the proxy's local settings. The properties below demonstrate this feature:
Greeter.Proxy=greeter:tcp -h localhost -p 4051
Greeter.Proxy.EndpointSelection=Ordered
These additional properties simplify the task of customizing a proxy (as you can with proxy methods) without the need to change the application's code. The properties shown above are equivalent to the following statements:
greeter = GreeterPrx(communicator, "greeter:tcp -h localhost -p 4061")
greeter = greeter.ice_endpointSelection(Ice.EndpointSelectionType.Ordered)
The list of supported proxy properties includes the most commonly-used proxy settings. The communicator prints a warning by default if it does not recognize a subordinate property.
Note that proxy properties can themselves have proxy properties. For example, the following sets the EndpointSelection
property on the default locator's router:
Ice.Default.Locator.Router.EndpointSelection=Ordered
Receiving a Proxy from an Operation
An application can also receive a proxy as the result of an Ice invocation. Consider the following Slice definitions:
interface Account { ... }
interface Bank
{
Account* findAccount(string id);
}
Invoking the findAccount
operation returns a proxy for an Account
object.
For example:
account = await bank.findAccountAsync("WXY-123456")
Of course, the application must have already created a proxy for the bank object using one of the techniques shown above.