Workflow Soluiton

 View Only
  • 1.  Code Script Component using C# does not work when it is published

    Posted Feb 26, 2016 07:50 AM

    Hello,

     

    I am using the Code script Component with a C# script. The Script is used to move a Computer in Active Directory to another OU, but using the whole AD path.

    Here is my script:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.DirectoryServices;
    namespace DynamicNamespace {
    public class DynamicClass {
    public void DynamicMethod(System.String from, System.String to)
    {
    DirectoryEntry theObjectToMove = new DirectoryEntry(from);
    DirectoryEntry theNewParent = new DirectoryEntry(to);
    theObjectToMove.MoveTo(theNewParent);
    
    }
    }
    }

    The script is working. I used the run Test in the Code script Component und debuged the workflow.

     

    The problem is that the Workflow waorks when i debug ist but when i publish the workflow it crashes at the Code Script Component.

    Do i have to install somthing an the IIS that it works?

     

    Greetings

     

    Turl

     



  • 2.  RE: Code Script Component using C# does not work when it is published

    Posted Feb 26, 2016 10:58 AM

    Have you seen "Custom C# Component – Adding a Computer to a Group in Active Directory" post by Africo, it might be of help.

    You'll need to either use a PrincipalContext within the Script or check the App Pool is running as an account that has the rights to do this.

    When testing in the generator it runs as the current user, who probably has rights.



  • 3.  RE: Code Script Component using C# does not work when it is published

    Posted Mar 01, 2016 02:50 AM

    Hello Alex,

     

    I know this article form Africo, if you take a greater look at it you will see i asked this.

    My C# Script and Component works fine when i debug the Workflow, but when i publish it, it does not work.

     

    Greets

     

     

    Turl



  • 4.  RE: Code Script Component using C# does not work when it is published
    Best Answer

    Posted Mar 01, 2016 03:49 AM

    Alex is absolutely right here - When you're debugging your WF it runs under your user context which most likely has permission to query your domain.

    When you publish your WF it runs under an application pool which has its own identity. You need to change the identity of this app pool to be your user or a user who has permission to query your domain.

    In IIS check which app pool your WF is using and then configure the identity of that app pool...

    Appools.PNG

    Alternatively you can set the username and password in the DirectoryEntry contructor however I wouldn't recommend hardcoding these values.

    https://msdn.microsoft.com/en-us/library/wh2h7eed.aspx

    Hope this helps

     



  • 5.  RE: Code Script Component using C# does not work when it is published

    Posted Mar 01, 2016 04:24 AM

    Try to add your active directory user and password in the line with new PrincipalContext(..., ) see example below.

    new PrincipalContext(ContextType.Domain,"mydomain", "CN=Computers,DC=fabrikam,DC=com","MyAdminAccount", "MyAdminPassword");

    This is what Alex means as well and what Africo describes under "Notes on Authentication..." in his article.



  • 6.  RE: Code Script Component using C# does not work when it is published

    Posted Mar 02, 2016 09:13 AM

    Hello Guys,

     

    I tried all your answers. No one helped me to solve my problem

    The publiched Workflow runs under an Account which is need to work on the NS server. Because there are two domains.

    We tried it with an account which as Adminrights in both domains. and used the new PrincipalContext in the script and it did not work.

     

    Do you have some other ideas how it can work?

     

    Greets

     

    Turl



  • 7.  RE: Code Script Component using C# does not work when it is published

    Posted Mar 02, 2016 10:53 AM

    If you create a new app pool, move the app to that, and set it to your account (or the account you were logged in as when it works in debug) does it work?



  • 8.  RE: Code Script Component using C# does not work when it is published

    Posted Mar 03, 2016 03:36 AM

    Make sure you're pointing to a specific domain controller that is configured as a global catalog for both domains.



  • 9.  RE: Code Script Component using C# does not work when it is published

    Posted Mar 09, 2016 03:17 AM

    Hello Guys,

     

    thank you for your help.

     

    now i got it to work. It was quite difficult to get it work, after much testing, we created a user which has rights in both domains and set him as user in the application pool.

     

    We also have the authentication in the C# Script.

     

    Whom can i give the solution? you all helped me out.

     

    Greetings

     

    Turl



  • 10.  RE: Code Script Component using C# does not work when it is published

    Posted Mar 10, 2016 04:20 AM

    I'm happy for you to give this one to Chris