Sunday, February 1, 2009

[11] ASP.NET Calling Clarity's Query Web Service

Here is an Example of ASP.NET calling Clarity's Query Web Service. This is useful in scenarios like .NET app wants to get Resource OBS by supplying ResourceID or say want to get Team member listing by passing in Projet ID...

Lets see first how it works...

1. Clarity creates a Web Service when a query is created. (Interesting.. Isn't it ?)
2. Any other system (.NET, Java, others ) can access this query and get data from Clarity. (if it knows Clarity login/pwd)
3. External System can supply Query Filter Criteria and get "Filtered" data from that query.

I am taking a simple example where .NET app will pass "user name" to Clarity and will in turn receive "Resource Manager". Here are the steps :

Step 1 : Create NSQL Query (QueryID = "res_manager") with two columns User Name and Resource Manager.
Step 2 : Create .NET Application, Add Web Reference to http://localhost/niku/wsdl/Query/res_manager Set Web Reference name say Q
Step 3 : Create a Webform and add Textbox to it named say TextBox1
Step 4 : Add following code in Page/Form load or under a button

------------------------------------------------------------------------
Dim QS As New Q.res_managerQueryService
Dim Q As New Q.res_managerQuery
Dim Auth As New Q.Auth

Dim Log As New Q.Login
Dim ClaritySessionID As String

Log.Username = "admin"
Log.Password = "clarity"

ClaritySessionID = QS.Login(Log)
Auth.SessionID = ClaritySessionID

Dim F As New Q.res_managerFilter
Dim QueryResult As New Q.res_managerQueryResult
Dim Rec As New Q.res_managerRecord

QS.AuthValue = Auth
Q.Code = "res_manager"
F.user_name = "jsmith"
Q.Filter = F
QueryResult = QS.Query(Q)
TextBox1.Text = QueryResult.Records(0).resource_manager_id

QS.Logout(ClaritySessionID)

--------------------------------------------------------------------------

* This example above would return only one Record as desired. For instances where multiple records are expected, you would need to loop though QueryResult.Records and get field elements.
** "MS Visual Web Developer 2008 Express Edition" is free to download..

5 comments:

  1. Hey Sangeet,
    I don't know much about XBL or WSDL, do you know of a good place to learn what it is and how to use it etc?
    We need a job that deletes completed jobs and there is an XBL in Clarity to do it thru the admin. I want to call the same XBL in batch mode using a age parameter based on job completion date. Please let me know your thoughts on this. Thanks!

    ReplyDelete
  2. THis has been really helpful, but if I apply a filter wildcard I get an XML exception. Or if I apply no filter i get the same. Any ideas? I have also converted the code to c#.

    ReplyDelete
  3. Ahh, got it sorted. If the returned data contains any Nulls, then the xml error is returned. A few COALESCE statements in my SQL fixed the problem and it now works a treat! Thanks again!

    ReplyDelete
  4. This might have saved my life right now.
    I.O.U a life.

    ReplyDelete
  5. Hey Sangeet,

    Firstly, great job on all the posts.

    I have a GEL script to call a web service and it works fine with a java based webservice but returns null when i call a .net webservice. Is there any environmental setting that needs to be done in clarity to get it working? There is a wcf service as well as a .aspx webservice that I am trying to call through GEL. I would appreciate any help on this.

    Thanks
    Sanjay

    ReplyDelete