Inhalte aufrufen

Profilbild

Newbie - Authentication and Batch Processing


  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
4 Antworten zu diesem Thema

#1 bee

bee

    Newbie

  • Members
  • 3 Beiträge

Geschrieben: 16 July 2014 - 06:36

Apologies if these are rookie questions  :)

I have read the documentation and examples from the codeplex site. 

I am playing around with smartstore and have created a simple console app that I intend to use to import Categories and Sub  Categories into the SmartStore website.

I have had a look at the web client tools. I have 2 questions...

 

1.) Visual Studio - Service reference

I initially added a service reference to my project e.g. http://server/odata/v1/$metadata

I could generate the context and the query by doing this:

var context = new SmartStore.Container(new Uri("http://server/odata/v1/"));
            var categories = from cats in context.Categories
                       select cats;
            foreach (var category in categories)
            {
                var name = category.Name;
            }

When i run this though,I get this error....

<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<m:error xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">\r\n  <m:code />\r\n  <m:message xml:lang=\"en-US\">An error has occurred.</m:message>\r\n  <m:innererror>\r\n    <m:message>Object reference not set to an instance of an object.</m:message>\r\n    <m:type>System.NullReferenceException</m:type>\r\n    <m:stacktrace>   at SmartStore.Web.Framework.WebApi.Security.WebApiAuthenticateAttribute.OnAuthorization(HttpActionContext actionContext)&#xD;\n   at System.Web.Http.Filters.AuthorizationFilterAttribute.OnAuthorizationAsync(HttpActionContext actionContext, CancellationToken cancellationToken)&#xD;\n--- End of stack trace from previous location where exception was thrown ---&#xD;\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&#xD;\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&#xD;\n   at System.Web.Http.Filters.AuthorizationFilterAttribute.&lt;ExecuteAuthorizationFilterAsyncCore&gt;d__2.MoveNext()&#xD;\n--- End of stack trace from previous location where exception was thrown ---&#xD;\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&#xD;\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&#xD;\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.&lt;SendAsync&gt;d__0.MoveNext()</m:stacktrace>\r\n  </m:innererror>\r\n</m:error>

From which Im understanding it to be a security issue...and my question is, how can I pass the security/authentication details into the request?? Using this method would be my preference due to the early bound generated stuff as well as the other methods on hand?

 

I thought that maybe i could add the authentication stuff when the request is built?

context.BuildingRequest +=context_BuildingRequest;

2.) OData batch processing

Having abandoned the above, I implemented the example from the codeplex,using the HttpWebRequest methods etc.

Now I wanted to know how to implement batch processing?I.e. submitt a request with for example '5 create request' in the single request instead of hitting the server 5times? I know odata supports batch processing but I couldnt see how to make it work with the SmartStore examples

 

 

Thanks!!



#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3371 Beiträge

Geschrieben: 16 July 2014 - 11:36

1.) The authentication is described here. The required information is exchanged by HTTP request headers.
For a sample please download the SmartStoreNET.WebApi.Client.Tools.zip.
 
2.) I never tried that. As far as I know the Web API does not support batch requests yet. It has to formally configured to be able to handle them
(as described here).

Schöne Grüße aus Düsseldorf,
Marcus Gesing


#3 bee

bee

    Newbie

  • Members
  • 3 Beiträge

Geschrieben: 16 July 2014 - 11:57

Hi Marcus,

In terms of the first question, I got the retrieve working fine. I set the header properties in the override method.

MERGE http://servername/odata/v1/Categories(1) HTTP/1.1
DataServiceVersion: 3.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Content-Type: application/json;odata=minimalmetadata
Accept: application/json, text/javascript, */*
Accept-Charset: UTF-8
User-Agent: Microsoft ADO.NET Data Services
SmartStore-Net-Api-PublicKey: *VALUE*
SmartStore-Net-Api-Date: 2014-07-16T09:43:43.1605228Z
Authorization: SmNetHmac1 *VALUE*
Host: server
Content-Length: 545
Expect: 100-continue

{"odata.type":"SmartStore.Core.Domain.Catalog.Category","Alias":null,"AllowCustomersToSelectPageSize":true,"CategoryTemplateId":1,"CreatedOnUtc":"2014-07-10T04:47:38.457","Description":null,"DisplayOrder":0,"HasDiscountsApplied":false,"Id":1,"LimitedToStores":false,"MetaDescription":null,"MetaKeywords":null,"MetaTitle":null,"Name":"Updated","PageSize":12,"PageSizeOptions":null,"ParentCategoryId":0,"PictureId":null,"PriceRanges":null,"Published":true,"ShowOnHomePage":false,"SubjectToAcl":false,"UpdatedOnUtc":"2014-07-10T04:47:38.457"} 

And response like..

HTTP/1.1 401 Unauthorized
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Server: Microsoft-IIS/8.0
WWW-Authenticate: SmNetHmac1
SmartStore-Net-Api-Version: 1 1.2
SmartStore-Net-Api-MaxTop: 120
SmartStore-Net-Api-Date: 2014-07-16T09:43:44.3640010Z
SmartStore-Net-Api-HmacResultId: 4
SmartStore-Net-Api-HmacResultDesc: InvalidSignature
X-AspNet-Version: 4.0.30319
Set-Cookie: smartstore.customer=b053a8b3-73dc-4b0a-831b-6ccdb9ab24ce; expires=Thu, 16-Jul-2015 09:43:44 GMT; path=/; HttpOnly
X-Powered-By: ASP.NET
Date: Wed, 16 Jul 2014 09:43:44 GMT
Content-Length: 0 

Appreciate the help

Update/create seems to be an issue though..I have fiddler on and when I call context.SaveChanges() it sends a MERGE request ...isnt meant to be a PUT request?

This is what the signature looks like...



#4 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3371 Beiträge

Geschrieben: 16 July 2014 - 12:15

SmartStore-Net-Api-HmacResultDesc: InvalidSignature
Means the signature passed in the request header does not match the one calculated by the Web API.
SmartStore-Net-Api-PublicKey is missing in your above post. For a header example see here.
 
Use POST to create, PUT to fully update and BATCH to partially update a record.
 
2.) I've created an issue for that.

Schöne Grüße aus Düsseldorf,
Marcus Gesing


#5 bee

bee

    Newbie

  • Members
  • 3 Beiträge

Geschrieben: 16 July 2014 - 12:21

Thanks for the help Marcus! Cheers