Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a BDC model in one of my SharePoint projects. This model ultimately needs to be deployed to 3 environments: Dev, Test and Production. Now my Dev environment only has one web application on port 80, and that's the one that my model gets deployed to auto-magically.

For Test and Production, it's a different story. Those environments have the main content and My Sites web applications both on port 80, using host headers. The trouble is that I can't deploy my BDC model in Test or Production without first telling the model which web application to deploy to. As far as I know, the only way to do that is to hard-code the absolute URL of the web application in the model prior to building the WSP. Since the URLs are different for each environment, I have to build different WSPs for Dev, Test and Production. Not cool. The problem is compounded by the fact that the URL is set in a source controlled file. So I have to check that file out, set the URL, build the WSP, deploy, test, and then undo my checkout. I would much prefer to have an automated build process handle this for me.

I've read elsewhere that this can be avoided by only having one web application on port 80. Is this recommended? It seems like not having My Sites on port 80 could be problematic. Are there any other recommendations or suggestions that I'm missing?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

If I understand you correctly you want to set the correct web application for your BCS model. Actually any web application that can connect to the BCS service application will do. I ran into the same issue and created a feature receiver for the BCS feature deploying the external content type to set the web application dynamically - so it works in all environments: dev, test, production. In my case all web applications had a BCS service application proxy and hence I simply used the first web application. That might be different in other scenarios.

public class ExternalContentTypesEventReceiver : ImportModelReceiver
{
    /// <summary>
    /// Occurs after a Feature is activated.
    /// The BDC deployment requires a valid site url property to retrieve a service context object.
    /// </summary>
    /// <param name="properties">An <see cref="T:Microsoft.SharePoint.SPFeatureReceiverProperties"/> object that represents the properties of the event.</param>
    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        var farm = properties.Feature.Parent as SPWebService;
        var application = farm.WebApplications.FirstOrDefault();

        var siteUrl = application.AlternateUrls.FirstOrDefault(u => u.UrlZone == SPUrlZone.Default).IncomingUrl;

        // Set site url property so that the external content type can be deployed.
        if (properties.Definition.Properties["SiteUrl"] == null)
        {
            properties.Definition.Properties.Add(new SPFeatureProperty("SiteUrl", siteUrl));
        }

        base.FeatureActivated(properties);
    }

    /// <summary>
    /// Features the deactivating.
    /// The BDC deployment requires a valid site url property to retrieve a service context object.
    /// </summary>
    /// <param name="properties">The properties.</param>
    public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
    {
        var farm = properties.Feature.Parent as SPWebService;
        var application = farm.WebApplications.FirstOrDefault(w => w.Sites.Count > 0);

        var siteUrl = application.AlternateUrls.FirstOrDefault(u => u.UrlZone == SPUrlZone.Default).IncomingUrl;

        if (properties.Definition.Properties["SiteUrl"] == null)
        {
            properties.Definition.Properties.Add(new SPFeatureProperty("SiteUrl", siteUrl));
        }

        base.FeatureDeactivating(properties);
    }

}
share|improve this answer
    
I had to call Update on the features properties after setting the value for SiteUrl (properties.Feature.Properties.Update()). Other than that this works like a charm. Thanks! –  jason.venema Jul 12 '13 at 13:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.