Monday, April 22, 2013

Remote Event Receiver Debugging (Using Developer Tools for VS 2012 Preview)

For Part 2 using Developer Tool for Visual Studio 2012 RTM

If we are developing SharePoint App for ProviderHosted / AutoHosted. We may have a requirement to create remote event receivers to handle events related to a list. 

The remove event receivers are actually handed using a service that needs to be hosted in another web project. When we do debugging web project is hosted on local machine's IIS Express. 

In this scenario it is quite difficult for both local IIS Express and remote SharePoint server to talk to each other due to network boundaries. To make debugging to work we require to do some manual changes in web.config of web project and AppManifest file of the SharePoint App Project. We also require to make use of Azure Service Bus.

For more information about Windows Azure Service Bus.

Steps to make debugging work.

  1. Create Autohosted SharePoint App with remote event receiver.
  2. Register for Microsoft Azure account.
  3. Create service Bus namespace. for e.g. if namespace is remoteevent then URL will be like https://{namespace-created}
  4. Right click web project. Select Nuget Package. Find Azure Service Bus and Install it.
  5. We need to make use of these values. Get these values according to your project.
    1. web project url on IIS Express: http://localhost:2917
    2. Bus Service namespace URL(from point 3): https://{namespace-created}
    3. Your unique web service address: https://{namespace-created}
    4. Default Issuer: (Open azure serice bus account Select your namespace and click "Access Key". write down Default Issuer)
    5. Default Key: (Open azure serice bus account Select your namespace and click "Access Key". write down Default Key)
    6. Client Secret:Value of Key "ClientSecret" inside section <appSettings> of web.config file
  6. Open web.config file of web project.
  7. Replace section <system.serviceModel> with following code
  8.   <bindings>

          <!--Used by app for SharePoint-->
          <binding name="secureBinding">
            <security mode="Transport" />

        <!-- Service Bus Binding -->
          <binding name="BasicHttpRelayBindingConfig">
            <security relayClientAuthenticationType="None" />

        <!-- Service Bus Binding -->
        <add  binding="basicHttpBinding" scheme="https" bindingConfiguration="secureBinding" />

        <!-- In this extension section we are introducing all known service 
            bus extensions. Users can remove the ones they don't need. -->
          <add name="transportClientEndpointBehavior" type="Microsoft.ServiceBus.Configuration.TransportClientEndpointBehaviorElement,  Microsoft.ServiceBus,  Version=,  Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          <add name="serviceRegistrySettings" type="Microsoft.ServiceBus.Configuration.ServiceRegistrySettingsElement, Microsoft.ServiceBus, Version=,Culture=neutral,  PublicKeyToken=31bf3856ad364e35" />
              name="basicHttpRelayBinding" type="Microsoft.ServiceBus.Configuration.BasicHttpRelayBindingCollectionElement, 
                        PublicKeyToken=31bf3856ad364e35" />

      <!-- Service Bus Binding -->
        <clear />
            name="{Replace with Point 6b}"
              address="{Replace with Point 6a}"
              address="{Replace with Point 6a}/mex"
              contract="IMetadataExchange" />
              address="{Replace with Point 6c}"
              behaviorConfiguration="sharedCredentials" />
          <behavior name="default">

            <!-- To avoid disclosing metadata information, 
                    set the values below to false before deployment. -->

            <!-- To receive exception details in faults for debugging 
                    purposes, set the value below to true. Set to false before 
                    deployment to avoid disclosing exception information. -->
            <serviceDebug includeExceptionDetailInFaults="true" />
          <behavior name="sharedCredentials">
                    issuerName="{Replace with Point 6d}"
                    issuerSecret="{Replace with Point 6e}" />
            <serviceRegistrySettings discoveryMode="Public" />

      <!-- Service Bus Binding -->

  9. In new <system.serviceModel> section replace
    {Replace with Point 6a}value you get from point 6 a
    {Replace with Point 6b}value you get from point 6 b
    {Replace with Point 6c}value you get from point 6 c
    {Replace with Point 6d}value you get from point 6 d
    {Replace with Point 6e}value you get from point 6 e

  10. Right click AppManifest file inside App project and click View code
  11. Replace </AutoDeployedWebApplication> with following code:
            ClientSecret="{Replace with Point 6f}" 
    AppUrl="{Replace with Point 6a};{Replace with Point 6c};" />
  12.  Open Element.xml file of you remote event receiver. Replace URL value with 6c.

That's all we need to change to make remote debugging enable.

No comments:

Post a Comment

Popular Posts