Tuesday 19 July 2011

Bing Maps Silverlight Control in Office 365

Recently, I was working on Geocoding with the Bing Maps Silverlight Control for a SharePoint 2010 Sandbox application. Everything was going awesome on my on-premise SharePoint 2010 environment but when I uploaded the application in Office 365, every time the application would load I would get a pop-up in IE asking whether to "Display Mixed Content?"

I googled for a solution and manged to learn that since the Office 365 environment was HTTPS and the Bing Maps GeoCoding web service was HTTP, I was being presented with this dialog box asking permission to display both HTTP and HTTPS content. This was also the reason why I was not getting the same pop-up on my on-premise SharePoint 2010 environment as it was also HTTP.

So the solution to this problem I thought was to find an HTTPS version of the Bing Maps GeoCoding web service so I made the following changes in my ServiceReferences.ClientConfig file:

1)Changed the URL of the web service to HTTPS
2)Changed the security mode of the basicHttpBinding from 'none' to 'Transport'

And voila! The annoying pop-up disappeared!

My final Service ServiceReferences.ClientConfig file looked like this:

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IGeocodeService" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647">
                    <security mode="Transport" />
                binding>
            basicHttpBinding>
            <customBinding>
                <binding name="CustomBinding_IGeocodeService">
                    <binaryMessageEncoding />
                    <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                binding>
            customBinding>
        bindings>
        <client>
            <endpoint address="https://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGeocodeService"
                contract="GeocodeService.IGeocodeService" name="BasicHttpBinding_IGeocodeService" />
            <endpoint address="http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc/binaryHttp"
                binding="customBinding" bindingConfiguration="CustomBinding_IGeocodeService"
                contract="GeocodeService.IGeocodeService" name="CustomBinding_IGeocodeService" />
        client>
    system.serviceModel>
configuration>