This project is read-only.

External Data (WCF) as a content part?

Topics: Core, Customizing Orchard, Writing modules
Feb 19, 2013 at 5:41 PM

I am trying to load data from an external source (WCF) doing the following steps:
  1. Added a Handler and with the OnLoading called the service, populating the ContentParts (lets call it a PersonPart) from the DTO's. also added an ActivatingFilter for the Part.
  2. Added a Driver, which ties the Part to the View (shape)
This works, for a simple PersonPart, however, my actual class is a composite object (PersonPart -> AddressParts)

My solution is similar to this example. look at the CustomerPartDriver class.

In its Display method, the ContentShape is being created by calling the content managers BuildDisplay for each child contentpart as follows

_contentManager.BuildDisplay(part.ShippingAddress, displayType)

This does not work for me as the parts I am loading do not have an associated ContentItem.

Is there a way to do this without the need for loading from the Orchard DB (ContentItems) so I can load from the WCF services and run all the associated drivers.

Thanks in advance
Feb 19, 2013 at 11:17 PM
There is no such thing as a part that does not have an associated ContentItem. But that doesn't mean it needs to have a DB-persisted record.
Feb 20, 2013 at 12:13 PM
Ok, im still trying to understand what is required to expose content from an external source, I was following this post and this post

So to load data from a external source, I require to create a ContentItem, is there an example of this, or a best practice, or can you give me some pointers on how (or where to start) to accomplish this.

In my solution we require a complex ContentItem ( Person [ContentItem] -> Addresses [List<ContentItem>] ).

many thanks

ps. I apologise for any miss use of the terminology, as I'm still new to this awesome framework

If it helps, here is some of the code we have to date:

public class DemoPersonHandler : ContentHandler, IDisposable
    private readonly ServiceClientWrapper<IPersonService> _serviceClientWrapper;

    public DemoPersonHandler() 
        _serviceClientWrapper = new ServiceClientWrapper<IPersonService>();

        Filters.Add(new ActivatingFilter<PersonPart>());

        OnLoading<PersonPart>((ctx, part) => 
            part = _serviceClientWrapper.Channel.GetPersonById(123);


    public void Dispose() 
Person Driver
public class DemoPersonDriver : ContentPartDriver<PersonPart>
    protected override DriverResult Display(PersonPart part, string displayType, dynamic shapeHelper)
        List<dynamic> addresses = part.Addresses.Select(x => _contentManager.BuildDisplay(x, displayType)).ToList(); //is this correct
        return ContentShape("Parts_PersonDetails", () => shapeHelper.Parts_PersonDetails(Person: part, Addresses: addresses));
Address Driver
public class DemoAddressDriver : ContentPartDriver<AddressPart>
    protected override DriverResult Display(AddressPart part, string displayType, dynamic shapeHelper)
        return ContentShape("Parts_AddressDetails", () => shapeHelper.Parts_AddressDetails(part));

Feb 20, 2013 at 8:48 PM
I'm a bit confused as to what the web service returns. In your handler, you assign the returned value to the local variable "part". What exactly does that achieve?

In any case, you do not require a content item to load external data.
If you do want to load external data and associate it with a content item, this is what I would do:
  1. The PersonPart is just a content part attached to whatever content item and has no record class.
  2. When a content item with this PersonPart attached is being loaded, you invoke the web service.
  3. The web service returns a POCO with information about the person. You copy the values of this POCO into properties of the PersonPart of the content item being loaded.
Mar 12, 2013 at 4:24 PM
my circumstances have updated, and thought it be best to create another discussion

many thanks for the input so-far :)