none
SP2013 Remote Event Receivers won't fire in on-premises provider-hosted app

    Question

  • I have been trying for nearly a week now to get a remote list item event receiver to fire in SP2013.  I have VS2012 RTM installed in Windows 7 (also tried with RC in the beginning) and I am deploying remotely to a LAN install of SP2013 Preview on Server 2008 R2 VM.  I have written other SP2013 apps for SharePoint successfully already and have been working with SP2013 Preview since the week it came out.

    I have tried to run the BasicDataOperations test project but I can't get it to deploy out of the box because it's not designed for a on-premises provider-hosted install. However I have created my own project following along with the video here: http://www.bing.com/videos/watch/video/remote-event-receivers-in-sharepoint-2013-demo/10ty138ca?cpkey=57522630-78e7-407a-9ab8-eef00a63580d%7C%7C%7C%7C.  

    Everything is setup exactly the same as demonstrated in the video and I can deploy the project and add items to the list but the events just never fire.  I have copied in the items from BasicDataOperations but had the same results.  

    I have used ItemAdded and ItemAdding and it has never fired my event handler code which just inserts a record into a table in a db on the SharePoint SQL server.  I have also tried other  code in the handlers like inserting a record into a different list.  I have tried and retried every little tweak and change but no luck. I'm not getting any error messages and I have searched and searched in the logs but haven't seen anything related. 

    Should this be working?


    Monday, September 17, 2012 4:27 PM

Answers

  • Well, I can't believe it but I finally got this working.  It wasn't quite as simple as just pointing the remote event receivers at my remote development machine because by default IIS Express doesn't allow remote connections.  It is important to note that based on what I have read and experienced you cannot debug remote event receivers at this time.  Someone please correct me if I'm wrong about that.

    Here is how to get remote event receivers working from a remote development machine.

    My web project is set to run from http://localhost:2145 for debugging.  My remote development machine is called hh-wks-robb. I have substituted "DomainUser" for my username. You will have to adjust your commands accordingly.  These steps assume you have remote debugging currently working with SharePoint 2013 Preview from a SharePoint Provider-Hosted App and a remote development machine. Other types of apps may be different and if you're developing directly on the server these steps are not necessary. All of these steps should be run from your development machine.

    First you need to allow remote connections to IIS on the correct port for all users.  Check the URL property for your web project to find the correct port. From an admin command prompt, run the following from your development machine:

    netsh http add urlacl url=http://hh-wks-robb:2145/ user=everyone

    Next you need to either disable windows firewall or allow the port through which is what I did.  In the same window, run this:

    netsh firewall add portopening TCP 2145 IISExpressWeb enable ALL

    You will get a message stating the command is deprecated but it still works. If someone wants to post the correct command using "netsh advfirewall add" instead that would be great.  

     After that you need to open the location 

    C:\Users\DomainUser\Documents\IISExpress\config\applicationhost.config

    Find the existing site node for localhost on the port your VS2012 dev server is running on.  Mine looked like this:

    <site name="ERTestWeb" id="11">
      <application path="/" aplicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="removed for brevity" />
      </application>
      <bindings>
        <binding protocol="http" bindingInformation="*:2145:localhost" />
      </bindings>
    </site>

    You need to add another binding using the name of your development machine.  Afterwards, mine looks like this:

    <site name="ERTestWeb" id="11">   <application path="/" applicationPool="Clr4IntegratedAppPool">     <virtualDirectory path="/" physicalPath="Removed for brevity" />   </application>   <bindings>     <binding protocol="http" bindingInformation="*:2145:localhost" />           
    <binding protocol="http" bindingInformation="*:2145:hh-wks-robb" />
      </bindings>
    </site>

    After this you will need to modify the web.config of your web project in Visual Studio to allow multiple bindings per site.  Right inside the "<system.serviceModel>" tag add this tag:

    <serviceHostingEnvironment multipleSiteBindingsEnabled="True"></serviceHostingEnvironment>
     

    Make sure to stop Visual Studio if it is debugging and then right click the icon for Visual Studio's IISExpress instance and click Exit to make sure it restarts and reloads all configs.  Push F5 to start debugging.  Log onto your SP2013 Preview server and try to navigate to http://hh-wks-robb:2145. You should get a message from the Web Server saying that Access is Denied.  You have succesfully connected to your development machine's web sever from the SharePoint server.

    Next, make sure you change the URL to your remote event receivers in the Elements.xml file to point at your development machine.  Mine looks like this:

    <Receivers ListUrl="Lists/List1">
          <Receiver>
            <Name>RemoteEventReceiver1ItemAdding</Name>
            <Type>ItemAdding</Type>
            <SequenceNumber>10000</SequenceNumber>
            <Url>http://hh-wks-robb:2145/RemoteEventReceiver1.svc</Url>
          </Receiver>
    </Receivers>

    Your SharePoint server app should now be able to execute the remote event receivers that are running on your development machine's local IISExpress instance.

    Many thanks to Rob Howard as well as the following resources for helping me figure this out.
    http://stackoverflow.com/questions/3313616/iis-express-enable-external-request
    http://stackoverflow.com/questions/5442551/iisexpress-returns-a-503-error-from-remote-machines
    http://blogs.msdn.com/b/rampo/archive/2008/02/11/how-can-wcf-support-multiple-iis-binding-specified-per-site.aspx
    Tuesday, September 18, 2012 6:57 PM

All replies

  • So this is an on-prem server, but it's on a separate server from the machine where you're developing the app?  When you're deploying the app, where are you deploying it to?  localhost?  A full url?  Are you deploying to an https location?

    Also, what list are you creating the item in, and what list are registering the event on?


    Monday, September 17, 2012 8:35 PM
  • Hi Rob, thanks so much for the reply.

    This is an on-prem server on my LAN which is a Server 2008 R2 VM running SP2013 Preview as well as all the local SharePoint development tools like Tools for SharePoint and VS2012.  

    I'm doing the actual development on my W7 workstation and deploying/debugging it via F5 to the SharePoint server.  The SharePoint Developer Site's URL is set as the Site URL for the SharePoint project and it is deploying and installing properly on the SharePoint site.   I can also access the Default.aspx page in the Web app via http://localhost:2145/Pages/Default.aspx (listed in development server URL).  

    I can access the list instance which I have added directly to the SP app and I can add items to the list.  I am using my isolated app domain URL to access the SP app which is apps-12341234.subdomain.domain.com.  I access my SP Developer site via http://subdomain.domain.com

    Other than for the Remote Event Receiver, I am not using the web app for anything else.  I can access the web service for the remote event receiver directly just fine. I have the local list instance set as the startup page for SharePoint app.  It is nearly identical to the BasicDataOperations test project only without any of the OAuth stuff in use.

    I have a local list instance named List1. It has a template type of 10000.  My event receiver is set to run on ListTemplateId="10000" but I have tried specifying the List URL directly and I have tried not specifying anything as well.

    I am NOT deploying to an HTTPS location.  

    Here is my test application which I can't get to work properly.  There may be something not quite right in it because as I was trying to fix this issue I somehow got an abandoned instance of the app which is stuck in SharePoint and I can't get either SP or VS to retract/uninstall it.  This is another issue I have run into a couple times now and I've had to work around it by creating a whole new app with a different name but that is an issue for a different thread.  :-P

    http://www.4shared.com/get/l7oa7xzI/ERTest.html




    Monday, September 17, 2012 9:14 PM
  • Rob, something you asked me just hit me in the face like a ton of bricks.  If I deploy my SP app to my remote server and I have the "Development Server URL" property on my web project set to a "localhost" type URL for debugging purposes, then when the SP app tries to call out to the web service I assume it is going to try looking for it at "localhost" and then it won't find it and thus not run the code?
    Monday, September 17, 2012 9:24 PM
  • Yeah, that's what I was thinking might be happening.  If you're deploying to localhost, that url will resolve to the SharePoint box when called during a remote event receiver, and the service won't be found.  Can you try deploying using the machine name instead of localhost?
    Tuesday, September 18, 2012 2:51 PM
  • Well, I can't believe it but I finally got this working.  It wasn't quite as simple as just pointing the remote event receivers at my remote development machine because by default IIS Express doesn't allow remote connections.  It is important to note that based on what I have read and experienced you cannot debug remote event receivers at this time.  Someone please correct me if I'm wrong about that.

    Here is how to get remote event receivers working from a remote development machine.

    My web project is set to run from http://localhost:2145 for debugging.  My remote development machine is called hh-wks-robb. I have substituted "DomainUser" for my username. You will have to adjust your commands accordingly.  These steps assume you have remote debugging currently working with SharePoint 2013 Preview from a SharePoint Provider-Hosted App and a remote development machine. Other types of apps may be different and if you're developing directly on the server these steps are not necessary. All of these steps should be run from your development machine.

    First you need to allow remote connections to IIS on the correct port for all users.  Check the URL property for your web project to find the correct port. From an admin command prompt, run the following from your development machine:

    netsh http add urlacl url=http://hh-wks-robb:2145/ user=everyone

    Next you need to either disable windows firewall or allow the port through which is what I did.  In the same window, run this:

    netsh firewall add portopening TCP 2145 IISExpressWeb enable ALL

    You will get a message stating the command is deprecated but it still works. If someone wants to post the correct command using "netsh advfirewall add" instead that would be great.  

     After that you need to open the location 

    C:\Users\DomainUser\Documents\IISExpress\config\applicationhost.config

    Find the existing site node for localhost on the port your VS2012 dev server is running on.  Mine looked like this:

    <site name="ERTestWeb" id="11">
      <application path="/" aplicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="removed for brevity" />
      </application>
      <bindings>
        <binding protocol="http" bindingInformation="*:2145:localhost" />
      </bindings>
    </site>

    You need to add another binding using the name of your development machine.  Afterwards, mine looks like this:

    <site name="ERTestWeb" id="11">   <application path="/" applicationPool="Clr4IntegratedAppPool">     <virtualDirectory path="/" physicalPath="Removed for brevity" />   </application>   <bindings>     <binding protocol="http" bindingInformation="*:2145:localhost" />           
    <binding protocol="http" bindingInformation="*:2145:hh-wks-robb" />
      </bindings>
    </site>

    After this you will need to modify the web.config of your web project in Visual Studio to allow multiple bindings per site.  Right inside the "<system.serviceModel>" tag add this tag:

    <serviceHostingEnvironment multipleSiteBindingsEnabled="True"></serviceHostingEnvironment>
     

    Make sure to stop Visual Studio if it is debugging and then right click the icon for Visual Studio's IISExpress instance and click Exit to make sure it restarts and reloads all configs.  Push F5 to start debugging.  Log onto your SP2013 Preview server and try to navigate to http://hh-wks-robb:2145. You should get a message from the Web Server saying that Access is Denied.  You have succesfully connected to your development machine's web sever from the SharePoint server.

    Next, make sure you change the URL to your remote event receivers in the Elements.xml file to point at your development machine.  Mine looks like this:

    <Receivers ListUrl="Lists/List1">
          <Receiver>
            <Name>RemoteEventReceiver1ItemAdding</Name>
            <Type>ItemAdding</Type>
            <SequenceNumber>10000</SequenceNumber>
            <Url>http://hh-wks-robb:2145/RemoteEventReceiver1.svc</Url>
          </Receiver>
    </Receivers>

    Your SharePoint server app should now be able to execute the remote event receivers that are running on your development machine's local IISExpress instance.

    Many thanks to Rob Howard as well as the following resources for helping me figure this out.
    http://stackoverflow.com/questions/3313616/iis-express-enable-external-request
    http://stackoverflow.com/questions/5442551/iisexpress-returns-a-503-error-from-remote-machines
    http://blogs.msdn.com/b/rampo/archive/2008/02/11/how-can-wcf-support-multiple-iis-binding-specified-per-site.aspx
    Tuesday, September 18, 2012 6:57 PM
  • Hi 02bluesuperroo,

    I got the similar problem, and it confused me for a while, I am developing inside a standalone instance, and has no way to debug the Remote event receiver.

    So we need to configure IIS express?

    Another thing that I am quite confused is that for a SharePoint-hosted app, the logics are all running in user's browser, does it mean when we click on the SharePoint list, the remote event receiver app is actually loaded in my browser?

    Sunday, April 14, 2013 11:48 PM
  • Check out this article on debugging remote event receivers in the RTM version of the Visual Studio tools:

    http://blogs.msdn.com/b/officeapps/archive/2013/03/21/update-to-debugging-sharepoint-2013-remote-events-using-visual-studio-2012.aspx

    Monday, April 15, 2013 2:42 PM