Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Highlighted
Tuned Listener
Posts: 23
Registered: ‎07-22-2011

SData Credentials

 

I wrote a business rule in an external assembly in which I try to use SData.

 

Here is a portion of the code that reads an SData entity (alxParameters) to set parameter values for calcultation purposes.

            IUser currentUser = BusinessRuleHelper.GetCurrentUser();
            ISDataService service = new SDataService("http://localhost:3333/sdata/slx/dynamic/-/", currentUser.UserName, "");
            var request = new SDataResourceCollectionRequest(service);
            request.ResourceKind = "alxParameters";
            AtomFeed feed = request.Read();

            foreach (AtomEntry entry in feed.Entries)
            {
                SDataPayload payload = entry.GetSDataPayload();
                ParamName = payload.Values["ParameterName"].ToString();
                ParamValue = Convert.ToDecimal(payload.Values["ParameterNumericValue"].ToString());
                if (ParamName == "KmRate1")
                {
                    KmRate1 = ParamValue;
                }
                if (ParamName == "KmRate2")
                {
                    KmRate2 = ParamValue;
                }
                if (ParamName == "KmCutoff")
                {
                    KmCutoff = ParamValue;
                }
            }

 

It works fine whan I am connected with a user that has a blank password.

Of course, I get an error "(401) Unauthorized" if the SLX user has a password.

 

Is there a way that we can use SDataService with the credentials of the connected user without having to hard code the password in a DLL ?

Highlighted
Tuned Listener
Posts: 23
Registered: ‎07-22-2011

Re: SData Credentials

I was able to achieve my goal using a different method.

 

            decimal KmCutoff = 0;
            decimal KmRate1 = 0;
            decimal KmRate2 = 0;
using (NHibernate.ISession sess = new SessionScopeWrapper(false)) { KmCutoff = Convert.ToDecimal(sess.CreateQuery("select max(ParameterNumericValue) from Sage.SalesLogix.Entities.alxParameter where ParameterName = 'KmCutoff'").UniqueResult()); KmRate1 = Convert.ToDecimal(sess.CreateQuery("select max(ParameterNumericValue) from Sage.SalesLogix.Entities.alxParameter where ParameterName = 'KmRate1'").UniqueResult()); KmRate2 = Convert.ToDecimal(sess.CreateQuery("select max(ParameterNumericValue) from Sage.SalesLogix.Entities.alxParameter where ParameterName = 'KmRate2'").UniqueResult()); }

 

I would still be interested to know if we can use SData in a business rule using the credentials of a conected user in SLXClient or SLXMobile.

 

Thanks.

Highlighted
Bronze Super Contributor
Posts: 152
Registered: ‎02-01-2011

Re: SData Credentials

SLXClient has it's own built-in sdata URL which is /slxdata.ashx/ ... works the same as sdata (e.g. /slxdata.ashx/$system/adapters)... this bypasses the credential requirements of the SData portal when the user is logged in to the SLXClient. As for Mobile, you're already logged in to the SData portal, so a Mobile app would have access to everything available through the SData service.

Andy Freeman
TrellisPoint, LLC
Highlighted
Tuned Listener
Posts: 23
Registered: ‎07-22-2011

Re: SData Credentials

Hi,

 

Didn't know about this URL....

 

Thanks a lot ! 

 

 

Highlighted
Employee
Posts: 85
Registered: ‎04-01-2009

Re: SData Credentials

Thanks for posting this answer. The topic in the Application Architect help mentions a couple examples you can review:

 

Consuming SData through the Web Client

When writing Web Client customizations that consume SData feeds, you can access the feeds directly through the Web Client portal so that it handles authentication. All SData feeds including the dynamic entity feeds are exposed to the Web Client through the slxdata.ashx handler. For example, the following two queries yield the same feeds:
 

                              http://localhost/sdata/slx/dynamic/-/accounts

http://localhost/SlxClient/slxdata.ashx/slx/dynamic/-/accounts
 

For examples of consuming an SData feed through the Web Client, review SalesOrderProducts.js and OpportunityProducts.js.