With the SDL Tridion 2011 arrival several integration opportunities came into the picture of content consumption and integration. In this post I will cover the basics about how to consume content from SDL Tridion by using non COM, .Net or java related technologies like adobe flex.
The techniques covered in this post can be used for a wide range of technologies which can support standard SOAP 1.1 web services.
Establishing connectivity between Core Services and Flex.
In order to establish connectivity in adobe flex we will use the mx.rpc.soap.WebService class. Not like .Net or Java, flex does not provide an abstraction layer like a stub which hides the low level details, in this case it is necessary to have a good understanding of the Core Services WSDL.
Not like WCF where we have the concepts of endpoint, binding, addresses, methods and contracts, in adobe flex we have to use standard WSDL concepts like ports, operations, messages and schemas.
The following WSDL fragment will show the list of Core Services ports that can be used in flex.
Not like WCF where we have the concepts of endpoint, binding, addresses, methods and contracts, in adobe flex we have to use standard WSDL concepts like ports, operations, messages and schemas.
The following WSDL fragment will show the list of Core Services ports that can be used in flex.
<wsdl:service name="CoreService2011">
<wsdl:port name="basicHttp" binding="i0:basicHttp">
<soap:address location="http://localhost/webservices/CoreService2011.svc/basicHttp" />
</wsdl:port>
<wsdl:port name="streamDownload_basicHttp" binding="i0:streamDownload_basicHttp">
<soap:address location="http://localhost/webservices/CoreService2011.svc/streamDownload_basicHttp" />
</wsdl:port>
<wsdl:port name="streamUpload_basicHttp" binding="i0:streamUpload_basicHttp">
<soap:address location="http://localhost/webservices/CoreService2011.svc/streamUpload_basicHttp" />
</wsdl:port>
</wsdl:service>
<wsdl:port name="basicHttp" binding="i0:basicHttp">
<soap:address location="http://localhost/webservices/CoreService2011.svc/basicHttp" />
</wsdl:port>
<wsdl:port name="streamDownload_basicHttp" binding="i0:streamDownload_basicHttp">
<soap:address location="http://localhost/webservices/CoreService2011.svc/streamDownload_basicHttp" />
</wsdl:port>
<wsdl:port name="streamUpload_basicHttp" binding="i0:streamUpload_basicHttp">
<soap:address location="http://localhost/webservices/CoreService2011.svc/streamUpload_basicHttp" />
</wsdl:port>
</wsdl:service>
streamDownload_basicHttp and streamUpload_basicHttp are not 100% soap 1.1 compatible since they use MTOM/XOP optimizations as message format and Flex does not support MTOM/XOP yet. I found a workaround for it by adding a new binding/endpoint combination that uses base64Array(Text) as message format which is the format used for interoperability.
For this post I have developed 3 actionscript classes than can be used to connect by using different kind of ports. CoreServicesClientBase is the base class used by BasicHttpClient and StreamDownloadClient
CoreServicesClientBase.cs
package com.tridion.cs {
import mx.rpc.events.*;
import mx.rpc.soap.*;
public class CoreServicesClientBase {
public const WSDL_URL:String = "http://localhost/webservices/CoreService2011.svc?singleWsdl";
public const CORESERVICE_NS:String = "http://www.sdltridion.com/ContentManager/CoreService/2011";
public const TRIDION_NS:String = "http://www.sdltridion.com/ContentManager/R6";
public const XSDI_NS:String = "http://www.w3.org/2001/XMLSchema-instance";
public const TRIDION_5_NS:String = "http://www.tridion.com/ContentManager/5.0";
protected var port:String;
protected var channel:WebService;
public function CoreServicesClientBase(loadListener:Function) {
channel = new WebService();
channel.useProxy = false;
channel.port = port;
channel.addEventListener(LoadEvent.LOAD, loadListener);
channel.loadWSDL(WSDL_URL);
}
}
}
BasicHttpClient.cs
package com.tridion.cs {
import mx.rpc.events.*;
import mx.rpc.soap.*;
import mx.rpc.wsdl.*;
import mx.rpc.xml.*;
import mx.utils.ObjectProxy;
public class BasicHttpClient extends CoreServicesClientBase {
public function BasicHttpClient(loadListener:Function) {
port = "basicHttp";
super(loadListener);
}
}
}
StreamDownloadClient.cs
package com.tridion.cs {
import mx.rpc.events.*;
import mx.rpc.soap.*;
import mx.rpc.wsdl.*;
import mx.rpc.xml.*;
import mx.utils.ObjectProxy;
public class StreamDownloadClient extends CoreServicesClientBase {
public function StreamDownloadClient(loadListener:Function) {
port = "streamDownload_base64_basicHttp";
super(loadListener);
}
}
}
*Note: As mentioned above, I added a new binding/endpoint "streamDownload_base64_bassicHttp" to the Core Services configuration file in order to disable MTOM/XOP but keeping it in the out of the box functionality.
The last step in this post will be the actual code to connect to the Core Services as shown in the code fragment below.
protected var channel:BasicHttpClient;
protected var downloadChannel:StreamDownloadClient;
protected function Init():void {
InitBasicHttpChannel();
InitDownloadHttpChannel();
}
protected function InitBasicHttpChannel():void {
var OnChannelLoaded:Function = function(event:LoadEvent):void {
event.currentTarget.removeEventListener(LoadEvent.LOAD, OnChannelLoaded);
trace("Connection is established using BasicHttp");
};
channel = new BasicHttpClient(OnChannelLoaded);
}
protected function InitDownloadHttpChannel():void {
var OnChannelLoaded:Function = function(event:LoadEvent):void {
event.currentTarget.removeEventListener(ResultEvent.RESULT, OnChannelLoaded);
trace("Connection is established using StreamDownload_BasicHttp");
};
downloadChannel = new StreamDownloadClient(OnChannelLoaded);
}
No comments:
Post a Comment