Wednesday, March 31, 2010

Using Workflow as web service Part – 2

Hi All,

If you haven’t read previous post, then I recommend you read Using Workflow as web service Part - 1 and then continue reading here.

Now in this post we will deep dive into real practical example where in we will create on workflow and then expose the workflow as web service and then we will consume that web service from one console application.

If you have gone through consuming web service in workflow post, you must have remembered that we created web service of calculating square root of given number and consumed it from our workflow. Well, we will do the same stuff here. However our workflow will act as web service here.

First let us create one project. Add project with type sequential workflow library. Name it as a SquareRootService.

Now right click the project and add new class. Name it ISquareRoot.cs.

Change the definition from class to interface.

Add following method definition.

double GetSquareRoot(double dblNumber);

Now drag WebserviceInput activity to the designer surface.

Bind the interfaceType property to the one that we create just now.



Set IsActivating property to true and MethodName to GetSquareRoot.



Select dblNumber proprty now, and click on … to bring the bind dialogue box and create new propoerty to bind it with dblNumber paramter of the input.



Now double click on InputRecieved method and generate it’s method.



Write down following code.

private void webServiceInputActivity1_InputReceived(object sender, EventArgs e)
{
double inputvalue = this.webServiceInputActivity1_dblNumber1;

webServiceOutputActivity1__ReturnValue_1 = (double)Math.Sqrt(inputvalue);


}


Go ahead and add one webserviceoutput activity. Bind it with InputActivity by giving inputactivityName to the webServiceInputActivity1. Set return value to the property



Now go ahead and right click on project and publish as a web service. This is really a cool feature that workflow provides. We need not to worry about anything. Just clicking on the button does the wonder.



Rename the newly generated file with SquareRootService.asmx

Now build that newly created web service.

Now add one console application for the test. And then add web reference; find web service in the solution.



Write down a very simple line to call a web service, which actually call our workflow.

static void Main(string[] args)
{

SquareRootService.Workflow1_WebService objService = new ConsoleWorkflowTest.SquareRootService.Workflow1_WebService();

double returnvalue = objService.GetSquareRoot(49);

Console.WriteLine("Square Root of 49 is : " + returnvalue.ToString());

Console.ReadLine();

}


And see the output.



That is it. Your job is done. Feel free to ask any query.

Tuesday, March 30, 2010

How to know the site template out of the box

Hi All,

Many times we come across to a situation where we cannot write a code and site is completely branded. Hence we cannot make a decision on which template the site is created with.

Here is a way to know which template site is created in. you must be a site collection administrator to do this.

1) Save site as template into site template gallery.
2) Save that template from gallery to your local machine.
3) Change the file extension to the .cab.
4) Extract manifest.xml file.
5) Check out the TemplateID in that.
6) This ID tells you which template the site was created in.


If site template is any of the below, then it is that site. If it’s above 1000, then it should be custom.

ID 0 = Global, Configuration 0 = Global Template
ID 1 = STS or SharePoint Team Site, Config 0 = Team Site
ID 1, Config 1 = Blank Site
ID 1, Config 2 = Document Workspace
ID 2 = MPS, or Meeting Place Sites, Config 0 = Basic Meeting Workspace
ID 2, Config 1 = Blank Meeting Workspace
ID 2, Config 2 = Decision Meeting Workspace
ID 2, Config 3 = Social Meeting Workspace
ID 2, Config 4 = Multipage Meeting Workspace
ID 3 = Centraladmin, config 0 - Central Admin Site
ID 4 = WIKI, Config 0 = Wiki site
ID5, Config 0 = Blog

Thanks to John Creevy for this solution.

Hope this will help you.

Monday, March 29, 2010

Using Workflow as web service Part - 1

Hi All,

In last post, we saw how we can use web service in our workflow. In other word, we saw how we can consume web service in our workflow. So now in this post, we will perform the reverse operation. We will see how our workflow acts as a web service and how other applications can use the workflow as a web service.

It is not simple as creating a web service and just taking a reference from other application. It is much more than this. However Visual studio and workflow give us the great command to convert the entire workflow in web service. How can we use this feature? Well, we will see it later in this post.

First let us understand what all things are required for exposing workflow as web service. We will be using WebServiceInput and WebServiceOutput activities.

We must have at least one Input and at least one output activity in the workflow. We cannot have input activity without associating output activity and we cannot have output activity without associating it with some input activity.

Let us go ahead and deep dive into webserviceinput activity.

For Webserviceinput activity you need to set some properties and handle one event. Properties are as follows.

1) Interface Type: Get or Set the Interface data type for which we are going to expose our methods as web methods.

2) Is Activating: At least one of the activities must have this property set to true. This indicates that by calling this method, use can start the workflow. You can have more than one activity which has this property set true. However, if this is the case, then all these activities can start the workflow.

3) MethodName: Name of the method that can be exported as web method.

Out of these three properties, Is Activating is default set to false. All above properties must have values assigned otherwise be ready for validation errors.

Let us go ahead and now understand webserviceoutput activity.

Webserviceoutput activity must be bind with any of the webserviceinput activity for which you want to return the output. You must assign InputActivity name to the webserviceoutputactivity, otherwise validation error will be thrown.

If method returns void, then no need to bind the return parameter to the webserviceoutput, else you need to bind the appropriate return parameter to the webserviceoutputactivity.

More than one webserviceoutputactivity can be associated with one webserviceinputactivity. Reason being, let us say, we have one if else condition and in that we are processing some activities. Or we have parallel activities going on and it can take any of the branch path, then for each path ends, we need to return some values. Hence for each path end can be bind to the single input activity.

There is one more activity that we have to use in the workflow if we want to expose the workflow as web service.

Webservicefalut activity is same as webserviceoutputactivity and must be bind with the webserviceinputactivity. Only difference is that webservicefaultactivity is binded to the field or parameter of type Exception and to be set in Fault parameter of this property. This will ensure that if anything goes wrong, we need to send the exception or proper message to the calling client method.

Read Using Workflow as web service Part – 2 for further reading.

Tuesday, March 23, 2010

Consuming web service in workflow

Hi All,

Workflow gives us very decent and useful activity for fetching web service from your local computer, network or even from internet.

Let’s us directly dive in to the way how we can achieve calling web service from the workflow. We do not have to write any custom activity or write some code to call web service method. All is given by the built in activity called Invoke web service.

To demonstrate the example here, I have created one small ASP.Net web service project which calculates the square root for the given number. Now I know. This is not something very useful in real world. As I said earlier as well, that I believe in giving simple example and then leave user to play with complex example. Most welcome for any query.

The moment you drop the Invoke Web Service activity on designer surface, it opens up the window asking you for the web service URL, it is very similar to what you see when you add web reference in normal ASP.NeT project.

I have web service in my own machine so I chose find in machine option, if you have to use any of the service residing anywhere in the world, give that as a URL and fetch the web service.

Workflow does all the work for you for creating proxy class ready for you to use and call the methods.

(You can take console workflow as test project here)

Interesting part of this activity is, it knows about the parameter binding. Now there can be one or more parameters for the specific method. Now I have default Helloworld method and my own method called GetSquareRoot which takes parameter of type double.

Moment you are done with setting the web reference with your web service, you can see the red circle error showing you that the MethodName is not set. Hence we are going to go ahead and set the MethodName to my own method.





Now as you can see we have been asked for setting the number value which is the parameter for the GetQuareRoot method. Also notice return value at the top in property window. There has to be a return value after calculating the square root. So go ahead and click on each one of them and bind it to new properties.

Just make sure that you create properties, not fields.





Now go ahead and add two more code activities. One before invokewebservice activity and one after that as shown in figure below.



Double click on Code Activity1 and write following code. Here we are setting the value of our input parameter that we have given as input to the method.

private void codeActivity1_ExecuteCode_1(object sender, EventArgs e)
{
this.InputNumber = 49;
}


And then double click on Code Activity2 and write following code. Here we are fetching the value from the web service and storing the result of the return value from web service method and then writing a simple statement so that we can come to know the output.

private void codeActivity2_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("Square root of " + this.InputNumber + " is : " + this.ReturnNumber);
Console.Read();

}


See the result. In this way we have now consumed web service from the workflow with the help of very helpful InvokeWebservice activity.

Monday, March 22, 2010

Result is out

Hi All,

Finally result is out. We asked people about problem that they face while using other browser than IE as far as SharePoint is concern. And it looks like MS has to work a lot on this fix. Well, let’s hope the next version 2010 does not have any browser problems.



Thank you for your responses.

Thursday, March 18, 2010

Creating custom activity in Workflow Part – 5

Hi All,

In previous parts, we saw how to deal with custom activities main validation logic, execution logic and some cosmetic tips. We will carry on some nice look and feel for the custom activity in this post as well.

If you haven’t gone through the previous post, then I recommend reading Creating custom activity in Workflow Part – 1 first and then continue reading further.

This post will show you the way we can implement an image associated with custom activity. When we drag and drop the custom activity on designer surface, we can attach PNG image of ideally 16 * 16 sizes.

We have to add ToolboxBitmap attribute to the CustomActivityDesigner class and the Custom Activity class with path to the 16 * 16 PNG picture.

If you apply ToolboxBitmap attribute to only Custom Activity class, then you will see the image on designer custom activity only. However, if you apply ToolboxBitmap attribute to CustomActivityDesigner class, then you will also find the image for custom activity in the toolbox as well.

Modify the classes as shown below.





And below is the result of applying attribute to both classes.



Now you will wonder I have given local path of my system. If you give this custom activity’s DLL to any other developer, how image will appear.

Well, answer to the question is very simple. No need to worry about image. Image is built as a part of embedded resource in assembly. So image will automatically be included with DLL.

I hope that you have liked this series of basic custom activity. Share with us your thoughts on this.

Read Creating custom activity in Workflow Part – 6 to explore more.

Monday, March 15, 2010

MOSS 2007 Excel Services - Part 1

Excel Services !
Its one of the most powerful feature of MOSS 2007. But have you tried to have a look into it?
If not , this article explains you the basic steps required to get hands on experience with Excel services. What all is required is listed below:
1. Shared Service Provider (SSP).
2. Excel file
3. A MOSS site
4. Document library
So now if you have created all of the above components, lets start….

STEP 1 : Making the document library trusted in central admin

In order to work with excel services, you need to make the document library where you are going to keep an excel file declare as ‘trusted’ in the central admin site.
Open the central admin site and click on the SSP name. In this case, the name of SSP is MySSP. Click on Excel Services Trusted File Locations and add a new trusted location. Mention URL of the document library in the site where you wish to keep the excel file. Keep rest of the settings as it is and click on OK. Refer to the screenshot below:



STEP 2: Configure settings of the document library

Open the document library where you want to keep the excel file. Go to settings à Advance Settings and as shown in the screenshot below, find the option ‘Opening browser - enabled documents’ and select the option ‘Display as a web page’ . Press OK to complete the step.





STEP 3 Publishing file to the document library

There are two ways to store the excel file in the document library.
a. Uploading the file directly to the library.
b. Publishing the file to the library.
As we all know how to upload a document to the document library, I would like to explain the other way.
Open the excel file and open the option of file menu as shown in the figure below. Select publish and then Excel Services. Specify the URL of the document library and that’s it. The excel file will be published or uploaded at the specified location. Of course, no need to mention that you need to have permissions on that library for uploading.







STEP 4 : Start of the excel calculation services

In order to view an published excel file, the ‘Excel Calculation Services’ needs to be running. You can start the service by navigating to Central Admin à Operation à Services on server and start this particular service.






That’s it. You have successfully completed the basic hands on for working with excel services. To see what is there in the excel, click on the title of the excel you published in the document library. Intended result is that it will open in the browser itself displaying the data in excel format.
More hands on and information on excel services coming in subsequent posts.
Contributed by 'The Ace'

Creating custom activity in Workflow Part – 4

Hi All,

As we are approaching to some final posts of the series, I feel happy to share these posts with you all and make you aware of all things related to custom activity.

If you have not read previous articles, I recommend you reading Creating custom activity in Workflow Part – 1 First.

Here in this post, we will talk about the visual designer for the custom activity. It has nothing to do with functionality, so definitely this is not something which is required, However it is something which is nice to have.

So let us go ahead and understand how we can create visual appearance of custom activity.

By default when you drag and drop any activity, you will observe the shape and coloring same for each and every activity. We can change the shape, background color, border of our custom activity to give new fresh look. Hence I refer this visualization change of custom activity as makeup of activity. (Remember I used this term in post 1). :)

To achieve this, we need to implement three steps instead of two steps like other posts that we did.

1) Create a class which inherits from ActivityDesigner.
2) Create class which inherits from ActivityDesignerTheme.
3) Add ActivityDesignerTheme attribute to the class which inherits from ActivityDesigner.
4) Add Designer attribute to the Custom activity class.

So let’s start. Add one more class to our custom activity project. Name it CustomActivityDesignerTheme



Then add CustomActivityDesigner class which inherits from ActivityDesigner and add attribute as shown in figure below.



And then add designer attribute to the Custom activity class.



Now again just compile whole custom activity project, add activity to the console application and see the result. You will see our customized theme for our custom activity that we’ve just created.




Read Creating custom activity in Workflow Part – 5 for further reading.

Friday, March 12, 2010

How to hide breadcrumb on single page in SharePoint

Hi All,

May times we require to hide bread crumb on single page. Say you have created one web part page in one document library and when you visit the web part page, you will see your site->document library->web part page name.

And you do not want your user to click on document library and see the content in it.

Hence we can place one content editor web part on the page and write down following code. This will remove the bread crumb from the page.

I am creating one demopage.aspx under shared document library.



You can observe bread crumb, where user can click on it and go to the shared documents.



Now add one content editor web part and add the following code into.

<style rel="stylesheet" type="text/css" />
td.ms-titlearea { display:none; }
</style>


Just make sure that you set chrome type to none under appearance.

Simple, see the result. Bread crumb is no more on the page.



That's it. Your job is done.

Wednesday, March 10, 2010

Creating custom activity in Workflow Part – 3

Hi All,

In last two articles, we saw how to create basic activity and how to work with validations of properties.

If you haven't gone through previous parts, then i recommend you reading Creating custom activity in Workflow Part – 1 and Creating custom activity in Workflow Part – 2 post before continue reading here.

In this post, I am going to talk on Tool box item with respect to custom activity. When we want to initialize properties or want to perform any action when activity is being added (dropped) on visual designer, we can use toolbox item for this.

To achieve this functionality we have to implement two steps.

1) Create Toolboxitem class for custom activity deriving from ActivityToolboxItem class.

2) Add ToolBoxItem attribute to the custom activity class.

These two steps shown above are basic steps that you will find in all parts of this series. Because we have to perform above same steps (just inheritance is a difference) to achieve stuff for custom activity.

So let us go ahead and assign default birth date to our birth date property (I know it does not sounds anything practical, However as I said if we use simple example then it makes life easier).

One more important point to mention here is that we have to mark our class serializable and also we have to call deserialze in the constructor of the class. Reasons for this, well it is a topic of its own. I will explain it later. As of now, we will implement them to demonstrate our example and anyhow it’s merely two-three lines to write.

Go ahead and add class to our custom activity project. Name it CustomActivityToolBoxItem.



Then, go to the custom activity class and add System.ComponentModel which will help you to add attribute to the class.

Add the newly build assembly to the toolbox and drag and drop on visual surface and see the magic. You will see default birth date property being set by our code.



Read Creating custom activity in Workflow Part – 4 for more activities.



Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com