3

I am trying to attach an Remote Event receiver in Provider hosted app for SharePoint online.I don't want to use azure account ACS connection string.Somehow i was able to find the solution and i created the provider hosted app and hosted on GoDaddy's server, and registered my app on my office 365 environment with proper domain and redirect url.But after deployment and installation of app in SharePoint online i am not able to find any remote event receiver attached on host list.

Please give your valuable suggestion on my problem. I want to use remote event receiver without having window azure account.I am sharing the steps which i have followed:-

  1. Registered my app on sharepoint online using "/appregnew.aspx" with proper domain and proper redirection url and recorded 'Client Id and Client Secret'.
  2. Created a SharePoint Hosted App using Visual studio by providing the proper url of SharePoint Online environment with domain( www.example.com ) and redirect url(https://www.example.com/Pages/Default.aspx). Updated the client id and client secret in web.config and AppManifest.xml file.
  3. Set the value to true for "Handle App Installed" from the property attribute. A new file is created "AppEventReceiver.svc".
  4. Written code for attaching the remote event receiver to the host web list of custom list template (the code part is correct as when i used with Azure account it worked for me)
  5. Once the "AppEventReceiver.svc" file added, my sharepoint hosted app gets converted into "Provider Hosted App"
  6. After completing the development i hosted my "*svc" service on my internet facing server(As i dont want to use Azure Account)

Recorded URL at which my *.svc service is hosted.

My codes are as following.

"AppManifest.xml" look likes

<?xml version="1.0" encoding="utf-8" ?>
<!--Created:cb85b80c-f585-40ff-8bfc-12ff4d0e34a9-->
<App xmlns="http://schemas.microsoft.com/sharepoint/2012/app/manifest"
     Name="RER_ProviderHostedApp" ProductID="{a0126186-626c-49d5-84ae-939cf39e2ee0}"  Version="1.0.0.0"
     SharePointMinVersion="16.0.0.0">
  <Properties>
    <Title>RER_ProviderHostedApp</Title>
    <StartPage>~url for start page?{StandardTokens}</StartPage>
    <InstalledEventEndpoint>~url of my *svc</InstalledEventEndpoint>
    <UninstallingEventEndpoint>~url of my *svc</UninstallingEventEndpoint>
  </Properties>
  <AppPrincipal>
    <RemoteWebApplication ClientId="~my client id" />
  </AppPrincipal>
  <AppPermissionRequests AllowAppOnlyPolicy="true" >
    <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web/list" Right="Manage" >
      <Property Name="BaseTemplateId" Value="100" />
    </AppPermissionRequest>
  </AppPermissionRequests>
</App>

My web.config looks like

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <appSettings>
    <add key="ClientId" value="~ my client id" />
    <add key="ClientSecret" value="~client secret" />
  </appSettings>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="debug">
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" >
    </serviceHostingEnvironment>
    <bindings>
      <basicHttpBinding>
        <!--Used by app for SharePoint-->
        <binding name="secureBinding">
          <security mode="Transport" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <protocolMapping>
      <add binding="basicHttpBinding" scheme="https" bindingConfiguration="secureBinding" />
    </protocolMapping>
  </system.serviceModel>
</configuration>

I am writing following code to attach remote event receiver to my host web list when app is installed.

private void HandleAppInstalled(SPRemoteEventProperties properties)
        {
            using (ClientContext clientContext =
                      TokenHelper.CreateAppEventClientContext(properties, false))
            {
                if (clientContext != null)
                {
                    List myList = clientContext.Web.Lists.GetByTitle(ListName);
                    clientContext.Load(myList, p => p.EventReceivers);
                    clientContext.ExecuteQuery();
                    bool rerExists = false;

                    foreach (var rer in myList.EventReceivers)
                    {
                        if (rer.ReceiverName == ReceiverName)
                        {
                            rerExists = true;
                            System.Diagnostics.Trace.WriteLine("Found existing ItemAdded receiver at "
                               + rer.ReceiverUrl);
                        }
                    }
                    if (!rerExists)
                    {
                        EventReceiverDefinitionCreationInformation receiver =new EventReceiverDefinitionCreationInformation();
                        receiver.EventType = EventReceiverType.ItemAdded;

                        //Get WCF URL where this message was handled
                        OperationContext op = OperationContext.Current;
                        Message msg = op.RequestContext.RequestMessage;

                        //receiver.ReceiverUrl = msg.Headers.To.ToString();
                        receiver.ReceiverUrl = remoteServiceUrl;
                        receiver.ReceiverName = ReceiverName;
                        receiver.Synchronization = EventReceiverSynchronization.Synchronous;
                        myList.EventReceivers.Add(receiver);
                        clientContext.ExecuteQuery();
                        System.Diagnostics.Trace.WriteLine("Added ItemAdded receiver at " + msg.Headers.To.ToString());
                    }
                }
            }
        }

Following is my *.svc service running on my internet facing server.

enter image description here

After completing all of the above steps when i package my code and installed the app in App catalog and then added the application to my SharePoint Online site. I checked using SharePoint Online Manager Tool

the remote event receiver was not attached to the host web list. I don't know what i missed here. Provide your valuable suggestion or else share the procedure how can i use remote event receiver without having azure account.

Thanks in Advance.

7

2 Answers 2

3

The following is some troubleshooting tips for remote event receivers.

https://msdn.microsoft.com/en-us/library/office/dn275975.aspx#sectionSection7

In particular, if you are using SharePoint Online and your remote event receiver uses https, you need a publicly accepted certificate from a certification authority.

0

I don't think its possible as host web list cant send messages to the local domain it needs to be done through the service bus as it acts as liaison between azure and local domain

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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