I need to create a WCF web service that takes a request from a classic ASP page/form and returns a pre-signed expiring URL in AWS S3. (I have a little WCF experience. I've previously been able to return a custom JSON formatted object.)
Now, I need to take a form post, get the name of the file requested from the form, and generate a pre-signed URL that expires in 24 hours, and return it. FYI, I don't do theory well. I need code examples.
How to I massage the following to do what I need it to?
Serving videos from Amazon S3 (this seems to be close to what I need. I can convert from VB to C# on my own, I just need more than this snippet to understand the total flow.
===SampleRestService.svc.cs===
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
namespace WcfService5
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class SampleRestService : ISampleRestService
{
public IEnumerable<APIContentObject> GetAllUsers()
{
IList<APIContentObject> myAPIContentObject = new List<APIContentObject>();
string strcon = ConfigurationManager.ConnectionStrings["iOSConn"].ConnectionString;
using (SqlConnection conn = new SqlConnection(strcon))
{
conn.Open();
string cmdStr = String.Format("SELECT FirstName, LastName, Email, pword, SignUpDate, enabled FROM Users");
SqlCommand cmd = new SqlCommand(cmdStr, conn);
SqlDataReader rd = cmd.ExecuteReader();
if (rd.HasRows)
{
while (rd.Read())
{
myAPIContentObject.Add(new APIContentObject(rd["FirstName"].ToString(),
rd["LastName"].ToString(),
rd["Email"].ToString(),
rd["pword"].ToString(),
rd["SignUpDate"].ToString(),
rd["enabled"].ToString(),
rd["FirstName"].ToString()));
}
}
conn.Close();
}
return myAPIContentObject;
}
}
[DataContract]
public class APIContentObject
{
[DataMember]
public string Name { get; set; }
[DataMember]
public string Excerpt { get; set; }
[DataMember]
public string Content { get; set; }
[DataMember]
public string ImageURL { get; set; }
[DataMember]
public string ThumbnailURL { get; set; }
[DataMember]
public string SluggedURL { get; set; }
[DataMember]
public string FileURL { get; set; }
public APIContentObject(string vName, string vExcerpt, string vContent, string vImageURL, string vThumbnailURL, string vSluggedURL, string vFileURL) //, decimal sal)
{
Name = vName;
Excerpt = vExcerpt;
Content = vContent;
ImageURL = vImageURL;
ThumbnailURL = vThumbnailURL;
SluggedURL = vSluggedURL;
FileURL = vFileURL;
}
}
}
====iSampleRestService.cs====
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
namespace WcfService5
{
[ServiceContract]
public interface ISampleRestService
{
[OperationContract]
//attribute for returning JSON format
[WebGet(ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/json/users")]
//method
IEnumerable<APIContentObject> GetAllUsers();
}
}
====web.config====
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="iOSConn" connectionString=" Server=HIDDEN;Database=HIDDEN;User ID=HIDDEN;Password=HIDDEN;Trusted_Connection=False;"/>
</connectionStrings >
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfService5.SampleRestService">
<endpoint address="/" behaviorConfiguration="REST" binding="webHttpBinding"
bindingConfiguration="" contract="WcfService5.ISampleRestService" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="REST">
<webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>