Calling SmartObject from ASP.NET getting exception

  • 22 January 2010
  • 5 replies
  • 0 views

Badge +8
This SmartObject returns a file from Sharepoint. It works when calling from the SmartObject tester but when attempting to call from code I am receiving the error + stacktrace:



Exception of type 'SourceCode.SmartObjects.Client.SmartObjectException' was thrown.



at SourceCode.SmartObjects.Client.SmartObjectClientServer.ExecuteScalar(SmartObject smartObject, DataTable inputTable) at SourceCode.SmartObjects.Client.SmartObjectClientServer.ExecuteScalar(SmartObject smartObject) at sharepointtrim.btnOrderSubmission_Click(Object sender, EventArgs e) in c:developmentwebASRAugmentationsharepointtrim.aspx.cs:line 180




The code in question:



try

{

_soServer.CreateConnection();

_soServer.Connection.Open(_cb.ToString());

Response.Write("Connected
");


SmartObject _soFile = _soServer.GetSmartObject("ASRAugXMLHolder");

Response.Write("soFile
");

_soFile.MethodToExecute = "GetSharepointDoc";

Response.Write(ddl1.SelectedValue + "
");


_soFile.Properties["FileLeafRef"].Value = ddl1.SelectedValue;

Response.Write("parameter done
");

_soServer.ExecuteScalar(_soFile);



}

catch (Exception ex)

{

Response.Write(ex.Message.ToString() + "

" + ex.StackTrace.ToString());

}


5 replies

Badge +8

You need to explicitly catch the SmartObject exception to get the exception thrown by services. Have a look at the following for some sample code, it has an example on extracting the real exception:


http://srikantha.wordpress.com/2007/09/18/code-manipulation-of-smart-objects/

Badge +8
The request failed with HTTP status 401: Unauthorized

This is a little bit disconcerting. The SO is working from the tester but not fron the called web page. I was assuming that the credentials from the app pool or the K2 server would be passed. It does not appear that this is the case. I found an article that mentions that credentials need to be passed in the proxy for the Sharepoint Webservice. Is there a way to set those in the SO, or am I way off base here?
Badge +4

Just make sure that your credentials is being passed correctly to the k2 server.


You can do this by running the K2 server in console mode.  From this you should also be able to see of you are authenticated using kerberos or NTLM.


You might need configure Kerberos, since calling the smart object from the K2 server does not do a double hop, but calling it from your web app means that your web app pass credentials to k2 which in turn needs to pass them on to the moss server.  This is a doulbe hop and K2 needs kerberos configured for this.


Henk

Badge +8
Kerberos was set up correctly but I also needed to be able to switch protocols on the exchange, or so it appears. I was able to do this by changing the delegation on the K2 host service account to 'All Protocols' and then delegating to the Sahrepoint service account. I found the solution in this posting.



http://www.k2underground.com/forums/t/11542.aspx



Thank you all for your help.

Badge +4
catch(SmartObjectException soEx) {

StringBuilder sb = new StringBuilder();

foreach(SmartObjectExceptionData soExData in soEx.BrokerData) {

sb.Append("Service: ");

sb.AppendLine(soExData.ServiceName);

sb.Append("Service Guid: ");

sb.AppendLine(soExData.ServiceGuid);

sb.Append("Severity: ");

sb.AppendLine(soExData.Severity.ToString());

sb.Append("Error Message: ");

sb.AppendLine(soExData.Message);

sb.Append("InnerException Message: ");

sb.AppendLine(soExData.InnerExceptionMessage);

throw new Application Exception(sb.toString(), soEx);

}


add that to your catch clause and see what the underlying error is...

Reply