3.2. Using the remote-service Tag

The remote-service configuration tag can be used to export existing Spring-managed services for direct remoting from a Flex client. Given the following Spring bean definition for a productService bean:

    
<bean id="productService" class="flex.samples.product.ProductServiceImpl" />
    	

and assuming the existance of a Spring-managed MessageBroker configured via the message-broker tag, the following top-level remote-service tag will expose the service for remoting to the Flex client as a remote service destination named productService:

<!-- Expose the productService bean for BlazeDS remoting -->
<flex:remote-service ref="productService" />
    	

By default, the remote service destination exposed to the Flex client will use bean name of the bean being exported as the service id of the destination, but this may be overridden using the service-id attribute on the remote-service tag.

An alternate way of using the remote-service tag is as a child element of an top-level bean definition. This is even more concise and works well if you don't have a need to keep your domain-layer bean definitions separate from infrastructure concerns such as Flex remoting. (Keep in mind that keeping them separate can lead to easier testability of the core domain layer.) The following achieves the an equivalent result to the previous example:

    
<bean id="productService" class="flex.samples.product.ProductServiceImpl" >
	<flex:remote-service />
</bean>
    	

The methods that are exposed to be called by the Flex client can be more tightly controlled through use of the include-methods and exclude-methods attributes of the remote-service tag. The BlazeDS channels over which the destination is exposed can also be controlled using the channels attribute. (These attributes are available whether using the top-level or the nested version.) A more extensively customized example would look something like:

<flex:remote-service ref="productService" include-methods="read, update" exclude-methods="create, delete" channels="my-amf, my-secure-amf" />
    	

The remote-service tag is transparently configuring a FlexRemotingServiceExporter bean instance for each bean being exported. The equivalent full bean syntax without the namespace support would be:

<!-- Expose the productService bean for BlazeDS remoting -->
<bean id="product" class="org.springframework.flex.messaging.remoting.FlexRemotingServiceExporter">
    <property name="messageBroker" ref="_messageBroker"/>
    <property name="service" ref="productService"/>
    <property name="serviceId" value="productService"/>
    <property name="includeMethods" value="read, update"/>
    <property name="excludeMethods" value="create, delete"/>
    <property name="channels" value="my-amf, my-secure-amf"/>
</bean>