calling SmartObjects method in C#

1k Views Asked by At

I created a SmartObject in K2 designer and I added the WCF url as service reference.

Below is the code

UserDetailsSvcClient userDetail = new UserDetailsSvcClient();
userDetail.Open();
UserDetails userDC = new UserDetails();
var userDetailsList = userDetail.UserDetailsSvc_Load(userDC);
userDetail.Close();

But the userDetailsList always remains as null.

Also the GetList Smart method is not appearing

2

There are 2 best solutions below

0
On

I am going to assume you have enabled endpoints on the K2 Server. If not ,refer to the following, Link to Endpoint Creation PS: You need to restart K2 Server before the changes are taken in to effect.

From the codes, seems like you are try to do a Load method. Load method will require a ID.

So for UserDetails userDC = new UserDetails();, add in the following:

userDC.Id = 1;

As for GetList, you dont need to pass it the UserDetails object.

var userDetailsList = userDetail.UserDetailsSvc_GetList(Null);
0
On

The issue was I did not authorize the client. I needed to add

userDetail.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

SO finally the code looked like this

UserDetailsSvcClient userDetail = new UserDetailsSvcClient();
    userDetail.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

userDetail.Open();
UserDetails userDC = new UserDetails();
var userDetailsList = userDetail.UserDetailsSvc_Load(userDC);
userDetail.Close();