Resources



Resources

Tech. Note: How to use PutObject with WSE 2.0 DIME attachments

Click for a printer friendly version of this document Printer Friendly Save to del.icio.us
Average Review:

Due to the Amazon S3 PutObjectInline method restrictions on object size, you are required to use the PutObject method for any object greater than 1 MB when making SOAP requests. This tech. note shows how to use PutObject with WSE 2.0 DIME attachments.

Details

Due to the Amazon S3 PutObjectInline method restrictions on object size, you are required to use the PutObject method for any object greater than 1 MB when making SOAP requests. The PutObject method is similar to the PutObjectInline method, except that it requires you to use a Direct Internet Message Encapsulation (DIME) attachment when making an Amazon S3 SOAP request. This tech note will outline how to make requests with DIME attachments by using the Web Services Enhancements for Microsoft .NET (WSE) 2.0 add-on to Microsoft Visual Studio .NET and the Microsoft .NET Framework.

Web Services Enhancements for Microsoft .NET (WSE) 2.0 SP2 can be downloaded here:
http://www.microsoft.com/downloads/details.aspx?familyid=FC5F06C5-821F-41D3-A4FE-6C7B56423841&displaylang=en

There are 2 major development obstacles that need to be addressed:

  1. A standard wsdl.exe generated proxy class does not support WSE 2.0.
  2. WSE 2.0 adds certain specific headers to the SOAP envelope that Amazon S3 does not yet support.

Solution

Here are the basic steps for using WSE 2.0 with Amazon S3. See the related code sample below for an implementation of this solution.

  1. Modify proxy class to support Microsoft.Web.Services2.

    Updating the wsdl.exe generated AmazonS3 proxy class to inherit from Microsoft.Web.Services2.WebServicesClientProtocol instead of System.Web.Services.Protocols.SoapHttpClientProtocol will allow us to add attachments to the RequestSoapContext of our request, and it will give us access to the Pipeline which manages the SOAP output filters.

    For example:

    using Microsoft.Web.Services2;
    public class AmazonS3 : WebServicesClientProtocol { ... }

  2. Remove all standard WSE OutputFilters from the Web Service Client Pipeline, and add a custom output filter to remove any other WSE headers that Amazon S3 does not yet recognize.

    Note: We are only using WSE for the DIME-related classes. All of the added headers related to WS-Security, WS-Addressing, and WS-Policy should be removed from our SOAP envelope because we do not need them.

Amazon S3 Error Codes

Sending a request with the WSE 2.0 headers will results in one of these two responses from Amazon S3:

  • 500 Internal Server Error : We encountered an internal error. Please try again. [if you only remove some of the headers]
  • 501 Not Implemented : A header you provided implies functionality that is not implemented.

Standard WSE 2.0 Output Filters

There are a number of standard output filters that need to be removed:

  • Microsoft.Web.Services2.Security.SecurityOutputFilter
  • Microsoft.Web.Services2.Referral.ReferralOutputFilter
  • Microsoft.Web.Services2.Policy.PolicyEnforcementOutputFilter

[proxy].Pipeline.OutputFilters.Remove(typeof(SecurityOutputFilter));
[proxy].Pipeline.OutputFilters.Remove(typeof(ReferralOutputFilter));
[proxy].Pipeline.OutputFilters.Remove(typeof(PolicyEnforcementOutputFilter));

You will also need to remove the <wsa:Action></wsa:Action> header. This can be done by writing a custom class (AWSFilters.cs) that inherits from the SoapOutputFilter class. By overriding the ProcessMessage method you can gain access to the SOAP envelope before it leaves your application.

// Add our custom filter to remove the unwanted WSE soap headers.
[proxy].Pipeline.OutputFilters.Add(new com.amazon.s3.filters.HeaderOutputFilter("wsa:")

Additional Notes

  1. Microsoft has replaced WSE 2.0 (DIME) with WSE 3.0 (MTOM). Amazon S3 does not currently support MTOM; please use DIME with Amazon S3.
  2. The provided code sample causes objects being streamed between a client machine and Amazon S3 to be stored in server memory. This is obviously a problem if you have many users transferring large amounts of data. You should address this by either rewriting the code that manages the streams, or by breaking large objects down into smaller pieces.
  3. The provided code sample uses the .NET FileUpload control to allow a user to select a file on their local system when putting an object to Amazon S3. The default size limit for a file to upload is 4096 KB (4 MB). By setting the maxRequestLength value in the web.config you can allow larger files to be uploaded. http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx


Related Documents
Type: Sample Code Amazon S3 Bucket Browser with DIME support in C#

Reviews
Create Review Write a Review

WSE SP3 available, Jul 9, 2007 2:23 AM
Reviewer: nomadixone
The latest package is available here: http://www.microsoft.com/downloads/details.aspx?familyid=1ba1f631-c3e7-420a-bc1e-ef18bab66122&displaylang=en It's a pity that Amazon doesn't support WSE 3.0, since the services created with it and WCF are not really backwards compatible with WSE 2.0 (as is par for the course with MS). *sigh*

Welcome, Guest Help
Login Login