Skip to main content

I am new to BlackPearl and new to K2, so I am hoping some of the more experienced people out there can help me out. I want to call a method on a web service from K2, supply it with some parameters and let it do its work. Seemed simple enough. Strangely though, I found that K2 doesn't appear to have a "web service" event wizard.


I don't want to have to write custom code every time I hook a new web service up to a K2 process, I'd prefer it to be just a little bit smarter than that.


So, failing that, does anyone have a solution? I can think of two, but I don't know how I'd go about achieving them:


a) Write my own event wizard which would allow me to select the web bethod to call and provide it with parameters. How do I write my own event wizard?


b) Write a generic thing which translates web services into smart objects with web methods corresponding to smart object methods. Has this been done before? Are there examples?


Thanks in advance

Ok, I have settled on (a) and realised that K2 BlackPearl has a "K2 Wizard Project" which ostensibly allows you to create a wizard.


 So far, I am able to generate the requisite dlls, which are copied into the K2 Bin directory and registered in the GAC, the only problem is they don't appear in my toolbox. I've tried manually adding them to the tool box using the "Choose items..." feature but although it seems to recognise the dlls as valid, they still refuse to appear in the tool box.


Has anyone had any experience successfully writing, compiling and installing a K2 Wizard in Blackpearl (sp1)?



Have you reset the toolbox?


 


Do do this Right-click on the toolbox and select

Reset Toolbox. Once the toolbox has reset, if you do not see the icon for your wizard, just for fun try repeating the reset.


If the icon still does not appear check the ConfigurationManager.config file for any errors.


 


Out of curiousity what did you use as a guide to building it.  There is a tutorial in the SDK but just wondering if that was it and if you found it useful.


I downloaded and installed the "goto" activity wizard sample from the k2 black market. That one didn't appear to install so I thought there may have been an incompatibility.


So, I started from scratch, using the goto wizard as an example, but as I mentioned above, to no avail.


Now that I "reset" the toolbox, I see the goto event wizard in the list!


So, this means I am on the right track. It looks like I need an install project to fiddle with config files and suchlike. I will do so and see where it gets me. I will also try get my hands on the SDK and find that tutorial.


Thanks for the help.


Excellent, glad to hear it.  And of course if you create a wizard do share on blackmarket...
Check out the blackmarket section on this site.  One of the examples is a service object that can be used to invoke web services from a SmartObject.  I've used it and it works great.  The only caveat is it only handles simple data types.

Thanks, David, for that potential solution, sounds very much like option (b) I'll look into it if the other option fails. What, precisely, is the name of the black market project? I could not find it in the teeny little scrolling tree thing.


I have taken the option (a) approach and I'm attempting to write my own wizard which actually appears to be working.


Chris: as far as the SDK is concerned, the tutorial was quite good & useful. That said, the example is a simple/limited one. I found the GOTO example on the black market quite useful in terms of filling in the gaps.


Hi,


 


In terms of writing a wizard, some things can trip you up quite easily. Attributes on the various classes have to be set correctly and if there is a mismatch, the items will not show in the toolbox, no matter what you do. Also as you quite correctly point out, you have to edit the config files.


 


I have put together a fairly complicated wizard which shows how to use each of the key items like the Context Browser, Dialogs, etc.

I have published some sample projects which demonstrate how to use the various K2 API’s and SDK’s which I though may be of interest to you.


 


The samples can be accessed via the K2 blackmarket or by using these links:


 




Should you have any further queries, please do not hesitate to contact us.


 


Kind regards,


Seb


You're right.  There isn't a blackmarket SmartObject project to consume web services.  I had seen a sample and thought it was on blackmarket.  Unfortunately, the sample was more of a preview and isn't available yet.


There is another way to invoke a web service from blackpearl.  When viewing a process inside Visual Studio, click the project references icon on the upper right of the design canvas.  Click the web tab and you can add a web service reference similar to how you do it in Visual Studio.  To invoke the web service, you'll need to user a server code event, but the code would be just like how you would do it in a standard .NET app.  One thing you might want to do is store the URL to the web service in an environment variable if it changes between dev-test-prod.


David


Thanks, Seb, for those links.


I am in the throes of writing my wizard, which has been reasonably successful so far. I have, however, got to the point where I need to put some code in my @safeitemname@.cs file.


This is not a problem. Unfortunately, however, my code requires references to some .Net libaries which are not already referenced for the process. Now, I know the wizard user can click the funny little add references button to add these references, but the whole point of the wizard is to avoid the necessity of the wizard user doing such things manually.


Is there a way to add these references programmatically? I am thinking there must be a way to do it in the PrepareCodeFiles method, but so far I am drawing blanks.


 ==========


David: My goal is to find a way to dynamically call any web service (or WCF service) from within K2 without having to add references and write custom code every time.


Hi,


In order to add a reference programmatically, you need to do three things:


a) Add a using statement for SourceCode.ProjectSystem and SourceCode.Workflow.Authoring


b) Get an instance of the SourceCode.Workflow.Authoring.Process which represents the current process in the PropertyWizard class


            if (e.Parent is Process)
            {
                _activeProcess = (e.Parent as Process);
            }
            else if (e.Parent is Activity)
            {
                _activeProcess = ((e.Parent as Activity).Process);
            }


c) Add a reference to it's references collection.


            if (!activeProcess.References.Contains((base.DataObject as WizardEvent).EventItem.Reference))
            {
                AssemblyReference ar = new AssemblyReference(myReference);


                ar.CopyLocal = true;


                activeProcess.References.Add(ar);
            }


This needs to be done in different places. Get the active process in the PropertyWizard class and pass this around to the pages where you select your assembly. On the page's OnDeActivate() method, add the reference.


 HTH


Seb


Excellent, works like a charm, thank you. Now all I have to do is get it all working 🙂

Reply