Posts

Showing posts from December, 2014

Great article on enabling cross origin requests in ASP.NET Web API 2

Useful to get the web api working on different URLs. http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api

How to definitively get Web API working with MVC 5.2

I was having a lot of trouble getting web api to working with MVC 5.2 recently. This article definitely works: http://stackoverflow.com/questions/26067296/how-to-add-web-api-to-an-existing-asp-net-mvc-5-web-application-project 

Tutorial: Using Google Cloud Storage from C# and .NET

There is almost no samples or documentation available anywhere for this, so I thought I would write this up myself as using the storage from GCS (similar to Amazon S3 and Azure Blob Storage) is one of the most basic things which people do with the cloud. The very first thing to do after creating the C# project in Visual Studio is to install the Nuget package mentioned here: https://www.nuget.org/packages/Google.Apis.Storage.v1/ There is a lot of confusion with multiple packages available, but this is what you want for GCS. Install-Package Google.Apis.Storage.v1 You are going to need to reference the following namespaces: using Google.Apis.Auth.OAuth2; using Google.Apis.Storage.v1; Setup the basic items you need for making the calls: private static ClientSecrets _clientSecrets = new ClientSecrets();         private static UserCredential _userCredential = null;         private static StorageService _storageService = new StorageService();         private const string

How to read the web responses from the results of the Amazon .NET API

Modify the source code to get this ability: AWSSDK_DotNet35\Amazon.Runtime\ AmazonWebServiceResponse .cs - Add a property to hold the HttpWebResponse object. awssdk_dotnet35\amazon.runtime\internal\transform\ httpwebrequestresponsedata .cs - Add a property to hold the HttpWebResponse object. AWSSDK_DotNet35\Amazon.Runtime\Internal\Transform\ IWebResponseData .cs - Add a property to hold the HttpWebResponse object. There are a series of classes which transfer the data from the internal objects to the output objects within the API: awssdk_dotnet35\amazon.s3\model\internal\marshalltransformations\ deleteobjectresponseunmarshaller .cs private static void UnmarshallResult (XmlUnmarshallerContext context,DeleteObjectResponse response) awssdk_dotnet35\amazon.s3\model\internal\marshalltransformations\ putobjectresponseunmarshaller .cs private static void UnmarshallResult (XmlUnmarshallerContext context,PutObjectResponse response) awssdk_dotnet35\amazon.s3\model\internal\m

How to enable setting the request headers for Get and Delete in Amazon SDK for .NET

From the source code, modify the below files: AWSSDK_DotNet35\Amazon.S3\Model\Internal\MarshallTransformations\GetObjectRequestMarshaller.cs AWSSDK_DotNet35\Amazon.S3\Model\Internal\MarshallTransformations\DeleteObjectRequestMarshaller.cs Modify the public IRequest Marshall (<parameter>) method by adding the below statements: var headers = <requestObject>.Headers; foreach (var key in headers.Keys)       request.Headers[key] = headers[key]; You will need to add the property for the headers to the classes (directly - not in their base classes): private HeadersCollection headersCollection = new HeadersCollection(); /// <summary>         /// The collection of headers for the request.         /// </summary>         public HeadersCollection Headers         {             get             {                 if (this.headersCollection == null)                     this.headersCollection = new HeadersCollection();                 return this.headersC

Getting around modifying the Amazon S3 SDK

It is useful to know the way around some of the code in the Amazon S3 SDK which are the main entry points. AWSSDK_DotNet35\Amazon.S3\ AmazonS3Client .cs – Contains the main entry points. This is the method where the HTTP request is made and the response is retrieved: AWSSDK_DotNet35\Amazon.Runtime\Pipeline\HttpHandler\ HttpWebRequestFactory .cs public virtual IWebResponseData GetResponse () This is the class which makes the HTTP request: AWSSDK_DotNet35\Amazon.Runtime\Pipeline\HttpHandler\ HttpHandler .cs public override void InvokeSync (IExecutionContext executionContext) This is the class where the ExecutionContext and its internal properties like RequestContext and ResponseContext are created: AWSSDK_DotNet35\Amazon.Runtime\ AmazonServiceClient .cs protected TResponse Invoke <TRequest, TResponse>(TRequest request, IMarshaller<IRequest, AmazonWebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller) where TRequest: AmazonWebServiceRequest

Is there anyway to programmatically handle Amazon S3 RequestTimeTooSkewed error without changing the local clock?

This is the solution. I had to figure it out myself: https://stackoverflow.com/questions/27367405/is-there-anyway-to-programmatically-handle-s3-requesttimetooskewed-error-without/27388502#27388502