How to Create videos with Stupeflix and Asp.Net (C#) - c#

I am working on a project to create videos from a series of images, videos and audios. The best API we could find online that suits our purpose was Stupeflix. Unfortunately Stupeflix doesn't come with a C# implementation examples. Since I couldn't find one online, I decided to put this question here.

Here is an example
Go https://developer.stupeflix.com/ and register for Api Key and Secret
Create an ASP.NET project in C#
Go to NuGet Packages Manager and add Microsoft.AspNet.WebApi.Client and Json.NET
Add Default page to your project and add Async="true" to the page declaration
Copy the code below and replace YourSecret with your Stupeflix secret.
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
namespace StupeflixTest
{
public class TaskObj
{
public Dictionary<string,string> tasks { get; set; }
public TaskObj(Dictionary<string, string> t)
{
tasks = t;
}
}
public partial class Default : System.Web.UI.Page
{
private const string URL = "https://dragon.stupeflix.com/";
protected async void Page_Load(object sender, EventArgs e)
{
string error = string.Empty;
try
{
Dictionary<string, string> taskParam = new Dictionary<string, string>();
taskParam.Add("task_name", "video.create");
taskParam.Add("definition", "<movie service='craftsman-1.0'> <body> <stack> <sequence> <effect type='sliding' duration='5.0'> <image filename='http://s3.amazonaws.com/stupeflix-assets/apiusecase/Canyon_Chelly_Navajo.jpg'/> <image filename='http://s3.amazonaws.com/stupeflix-assets/apiusecase/Ha_long_bay.jpg'/> <image filename='http://s3.amazonaws.com/stupeflix-assets/apiusecase/Monument_Valley.jpg'/> </effect> </sequence> </stack> </body></movie>");
TaskObj obj = new TaskObj(taskParam);
//uncomment the line below to see the resultant json object
//string str = JsonConvert.SerializeObject(obj);
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Secret YourSecret");
client.BaseAddress = new Uri(URL);
// await response.
var response = await client.PostAsJsonAsync("v2/create", obj); // Blocking call!
if (response.IsSuccessStatusCode)
{
var jsonResp = response.Content.ReadAsStringAsync().Result;
var jsonArray = JsonConvert.DeserializeObject<dynamic>(jsonResp);
string resultKey = jsonArray[0].key.Value;
string taskProgressUrl = URL + "v2/status?tasks=" + resultKey;
}
else
{
error = string.Format(#"{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
}
}
catch (Exception ex)
{
error = ex.Message;
}
}
}
}

Related

HTTP status code 500 when querying an API from a C# program, except the API works

I need to use another company's API to query data using POST requests.
The API works (= I receive all the data with no errors) when I query it from the swagger website using the UI, but when I do it from my C# program I get a 500 Internal Server Error.
Where should I be looking for the problem ? Is there a way to get a more detailed error message ?
Edit (added code) :
using System;
using System.Data.Entity;
using System.Data.Entity.Core.Mapping;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Infrastructure.Interception;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.Serialization;
using System.Text;
namespace credex_distribution_offers_to_interfaces
{
class Program
{
private const string jsonMediaType = "application/json";
static void Main()
{
FetchJSONAndInsertToDB();
}
private static bool FetchJSONAndInsertToDB()
{
var baseServiceUrl = new Uri("a valid url");
Root rootObject;
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(jsonMediaType));
try
{
string token = FetchToken(httpClient, baseServiceUrl);
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token);
}
catch (Exception e)
{
return false;
}
try
{
rootObject = FetchDistributionLookupOffers(httpClient, baseServiceUrl, 29612, 29613, 29614, 29617, 29621);
}
catch (Exception e)
{
return false;
}
}
// database related stuff...
// ...
return true;
}
[DataContract]
public class MortgageForDistributionLookupInputDto
{
public int[] OfferNumbers { get; set; }
}
private static Root FetchDistributionLookupOffers(HttpClient aHttpClient, Uri aBaseServiceUrl, params int[] aOfferNumbers)
{
var input = new MortgageForDistributionLookupInputDto()
{
OfferNumbers = aOfferNumbers
};
var lookup = aHttpClient.PostAsync(new Uri(aBaseServiceUrl, "v1/MortgageDetails/InvestorLookupOffers"), PayloadFor(input)).Result;
if (lookup.StatusCode != HttpStatusCode.OK)
{
throw new Exception("Fetching investor lookup offers failed with HTTP status code '" + lookup.StatusCode + "' : " + lookup.ReasonPhrase + "}");
}
var obj = ValueFor<Root>(lookup.Content);
return obj;
}
private static HttpContent PayloadFor<T>(T aObject)
{
return new StringContent(aObject.SerializeJson(), Encoding.UTF8, jsonMediaType);
}
private static T ValueFor<T>(HttpContent aHttpContent)
{
//var content = aHttpContent.ReadAsStringAsync();
return aHttpContent.ReadAsStreamAsync().Result.DeSerializeJson<T>();
}
private static string FetchToken(HttpClient aHttpClient, Uri aBaseServiceUrl)
{
var login = new LoginRequest()
{
UserName = "some user name",
Password = "some password"
};
var authResult = aHttpClient.PostAsync(new Uri(aBaseServiceUrl, "api/Login"), PayloadFor(login)).Result;
if (authResult.StatusCode != HttpStatusCode.OK)
{
throw new Exception("Fetching authentication token failed. Reason : " + authResult.StatusCode + " -> " + authResult.ReasonPhrase);
}
return authResult.Content.ReadAsStringAsync().Result.Trim('"');
}
}
}

How to Seriailize an c# object into Json, while using httpClient?

I have a little program which should communicate with "Slack". In an older Version I used "Dictionary<string, string>" and then put them into UrlEncodedContent - which worked fine.
Now I am trying to create a Json-object, using Newtonsoft's Nuget-package and (in my opinion) formatting my object the way they say on their website.
Problem is, when I try to make a simple request, my program just runs to one specific line in the code(var response = await _httpClient.SendAsync(request);) and then it just ends. It doesn't throw an exception or display any kind of message, it simply ends on this line. I went through my code step by step while debugging, that's how I know it ends on exactly this line. And I just don't know why!
Now my code:
First, my object...
namespace BPS.Slack
{
public class JsonObject
{
//generally needed parameters
[JsonProperty("ok")]
public bool ok { get; set; }
[JsonProperty("error")]
public string error { get; set; }
[JsonProperty("channel")]
public string channel { get; set; }
[JsonProperty("token")]
private string token = "xoxp-MyToken";
[JsonProperty("as_user")]
public bool as_user = false;
[JsonProperty("username")]
public string username { get;set; }
//--------------------------------
//only needed for textmessages
[JsonProperty("text")]
public string text { get; set; }
//--------------------------------
//for posting messages with data attached
[JsonProperty("initial_comment")]
public string initial_comment { get; set; }
[JsonProperty("file")]
public string file { get; set; }
[JsonProperty("channels")]
public string channels { get; set; }
//--------------------------------
//for getting the latest message from a channel
[JsonProperty("count")]
public string count = "1";
[JsonProperty("unreads")]
public bool unreads = true;
}
}
now the client:
namespace BPS.Slack
{
public class BpsHttpClient
{
private readonly HttpClient _httpClient = new HttpClient { };
public Uri UriMethod { get; set; }
public BpsHttpClient(string webhookUrl)
{
UriMethod = new Uri(webhookUrl);
}
public async Task<HttpResponseMessage> UploadFileAsync(MultipartFormDataContent requestContent)
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, UriMethod);
request.Content = requestContent;
var response = await _httpClient.SendAsync(request);
return response;
}
}
}
and the main
namespace TestArea
{
class MainArea
{
public static void Main( string[] args)
{
try
{
Task.WhenAll(SendMessage());
}
catch(Exception ass)
{
Console.WriteLine(ass);
Console.ReadKey();
}
}
private static async Task SendMessage()
{
var client = new BpsHttpClient("https://slack.com/api/im.history");
JsonObject JO = new JsonObject();
JO.channel = "DCW21NBHD";
var Json = JsonConvert.SerializeObject(JO);
var StringJson = new StringContent(Json, Encoding.UTF8);
MultipartFormDataContent content = new MultipartFormDataContent();
content.Add(StringJson);
var Response = await client.UploadFileAsync(content);
string AnswerContent = await Response.Content.ReadAsStringAsync();
Console.WriteLine(AnswerContent);
Console.ReadKey();
}
}
}
I had the same problem in my older version, BUT only as I wanted to DEserialize an answer I got from Slack. It had to do with my object I tried do deserialize the answer into. But this time I can not figure out what's wrong. But, as I said, I do not have any experience with using serialized objects as Json-property to send requests... anyone has an idea what is wrong with my code?
EDIT: This problem is kinda solved. But there is a follow up problem.
Okay, I found out that the reason for the abprubt termination was the
Task.WhenAll(SendMessage());
it should be
Task.WaitAll(SendMessage()); Why??? Somebody said I should use WhenAll, but obviously it doesn't work properly in this case...
Now I get a response from Slack, but now a different problem has arisen. When I use this method:
public async Task<HttpResponseMessage> UploadFileAsync(MultipartFormDataContent requestContent)
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, UriMethod);
request.Content = requestContent;
var response = await _httpClient.SendAsync(request);
return response;
}
I allways get the answer:
{"ok":false,"error":"invalid_form_data"}
so I tried to explicitly tell it the 'mediaType', I tried "application/json" and others, but with all of them I get the same error. Here is the full method that calls the upper mehtod:
private static async Task SendMessage()
{
var client = new BpsHttpClient("https://slack.com/api/chat.postMessage");
JsonObject JO = new JsonObject();
JO.channel = "DCW21NBHD";
JO.text = "This is so much fun :D !";
var Json = JsonConvert.SerializeObject(JO, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
var StringJson = new StringContent(Json, Encoding.UTF8, "application/json");
var requestContent = new MultipartFormDataContent();
requestContent.Add(StringJson);
var Response = await client.UploadFileAsync(requestContent);
string AnswerContent = await Response.Content.ReadAsStringAsync();
}
When I use this method:
public async Task<HttpResponseMessage> SendMessageAsync(FormUrlEncodedContent content)
{
var response = await _httpClient.PostAsync(UriMethod, content);
return response;
}
so bascially I am passing "FormUrlEncodedContent" instead of "MultipartFormDataContent" in this, and then I get the response I want and can work wiht it. BUT this i of little use to me since I have to use "MultipartFormDataContent" to be able to send files with my requests.
Anyone have an idea what is failing here? Why does it not like the one content-type but the other one? I'd be gratefull for tipps and ideas!
You are serializing your object to Json and then adding it to a Multipart body, that's quite strange. Unless you're uploading binary data (eg Files), there is no need to use MultipartFormDataContent.
You are can directly post your JsonObject serialized as JSON:
public async Task<HttpResponseMessage> PostJsonAsync(StringContent content)
{
var response = await client.PostAsync(url, content);
return response;
}
var client = new BpsHttpClient("https://slack.com/api/im.history");
JsonObject JO = new JsonObject();
JO.channel = "DCW21NBHD";
var Json = JsonConvert.SerializeObject(JO);
var StringJson = new StringContent(Json, Encoding.UTF8);
var Response = await client.PostJsonAsync(content);
Also this is should be POST on the UploadFileAsync function.
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, UriMethod);
so I figured out that in the Main() the problem was this:
Task.WhenAll(SendMessage());
I should instead use:
Task.WaitAll(SendMessage());
Anyone who has more knowledge on this, please elaborate why!

How do I get JWT working in Autorest generated SDK? (ASP.NET Core 2.0)

I want to be able to login to my identity database with user name and password and retreive a JWT. Then I want to use the JWT to access data securely from my API.
I found out that the SDK code generated by VS2017 uses an old version of autorest, so I have switched to using Azure Autorest
The api and the SDK are both ASP.NET Core 2.0
To generate the SDK I use
AutoRest -mynamespace mytrack.Client -CodeGenerator CSharp -Modeler
Swagger -Input swagger.json -PackageName mytrack.client -AddCredentials true
The versions show as
AutoRest code generation utility [version: 2.0.4262; node: v8.11.2]
I have written my test as
using System;
using System.Threading.Tasks;
using Microsoft.Rest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using swagger; // my name space from the autorest command, not to be confused with swagger itself.
using swagger.Models;
namespace CoreClientTest
{
[TestClass]
public class MyTests
{
[TestMethod]
public void TestMethod1()
{
try
{
GetMyJob().Wait();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
private static async Task GetMyJob()
{
var tokenRequest = new TokenRequest
{
Username = "myusername",
Password = "mypassword"
};
var credentials = new TokenCredentials("bearer token");
var uri = new Uri("https://localhost:44348", UriKind.Absolute);
var tokenClient = new Track3API(uri, credentials);
var tokenResponse = await tokenClient.ApiRequestTokenPostWithHttpMessagesAsync(tokenRequest);
var tokenContent = await tokenResponse.Response.Content.ReadAsStringAsync();
var tokenString = JObject.Parse(tokenContent).GetValue("token").ToString();
var creds2 = new TokenCredentials(tokenString);
var client2 = new Track3API(uri, creds2);
var result = await client2.ApiJobsByIdGetWithHttpMessagesAsync(1);
var response = result.Response;
Console.WriteLine(response.ToString());
}
}
}
I can see that the result has OK and I can see the token in it.
I cant see the return job
The method in the api has
[Produces("application/json")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[Route("api/jobs")]
public class JobController : Controller
{
/// <summary>
/// Returns Job Header for Id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}", Name = "Get")]
public IActionResult Get(int id)
{
var header1 = new JobHeader
{
JobNumber = "1234",
Id = id,
CustomerPurchaseOrderNumber = "fred"
};
return Ok(header1);
}
}
You should apply the DataContract attribute over the class so that when RestClient consumes the service reference, it also generate the types.
Read it here.
You should also attach DatamMember attribute on Property. See below example
[DataContract]
class Person
{
[DataMember]
public string Name {get; set; }
[DataMember]
public int Id {get; set; }
public Person(string name, int id)
{
this.Name = name;
this.Id = id;
}
}
When Rest Client consume the service, it will generate the classes at client side for those classes which are attributed with DataContract.
Finally it is working.
I found a tip at Andrei Dzimchuk's blog on setting up the token
using System;
using System.Threading.Tasks;
using Microsoft.Rest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using swagger;
using swagger.Models;
namespace CoreClientTest
{
[TestClass]
public class MyTests
{
[TestMethod]
public void TestMethod1()
{
try
{
GetMyJob().Wait();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
private static async Task<JobHeader> GetMyJob()
{
var tokenRequest = new TokenRequest
{
Username = "myusername",
Password = "mypassword"
};
var credentials = new TokenCredentials("bearer token");
var uri = new Uri("https://localhost:44348", UriKind.Absolute);
var tokenClient = new Track3API(uri, credentials);
var tokenResponse = await tokenClient.ApiRequestTokenPostWithHttpMessagesAsync(tokenRequest);
var tokenContent = await tokenResponse.Response.Content.ReadAsStringAsync();
var tokenString = JObject.Parse(tokenContent).GetValue("token").ToString();
var creds2 = new TokenCredentials(tokenString);
var client2 = new Track3API(uri, creds2);
var result = await client2.ApiJobsByIdGetWithHttpMessagesAsync(1);
string resultContent = await result.Response.Content.ReadAsStringAsync();
var job = JsonConvert.DeserializeObject<JobHeader>(resultContent);
Console.WriteLine(job.JobNumber);
return job;
}
}
}

Why is MySQL result OK when called from browser, but empty or NULL when called from C#?

I'm trying to do a webrequest from my C# Windows application to my website,
but the desired result is empty or null when called only from C# but not from website where it works as expected.
Before I do my request, I need to begin with a login request which works as expected and does indeed return the correct value.
IMPORTANT EDIT:
I tried to copypaste my PHP code in to my login.php file and it does work in C# and returns the correct count-value.
Is my HttpClient not properly configured maybe?
My PHP test code looks as following:
<?php
session_start();
if(!isset($_SESSION['user'])){ header("Location: index.php"); }
include_once 'dbconnect.php'; //contains $db
$sql = "SELECT * FROM myTable"; //contains two rows
$sql_res = mysqli_query($db, $sql);
$proxyCount = mysqli_num_rows($sql_res);
$echo "Count: ".$proxyCount;
?>
And my C# looks like this:
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Net.Http;
using ModernHttpClient;
using Newtonsoft.Json;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void log(string str)
{
logbox.AppendText(str + Environment.NewLine);
}
private string host = "http://www.mywebsite.com/";
private HttpClient httpClient = new HttpClient(new NativeMessageHandler());
private async Task<string> request(string target, Dictionary<string, string> _parameters)
{
string uri = host + target;
using (HttpResponseMessage response = await httpClient.PostAsync(uri, new FormUrlEncodedContent(_parameters)))
return new StreamReader(await response.Content.ReadAsStreamAsync()).ReadToEnd();
}
private async void button1_Click(object sender, EventArgs e)
{
string loginResp = await request("login.php", new Dictionary<string, string> { { "username", "user" }, { "password", "password" } });
log(loginResp);
}
private async void button2_Click(object sender, EventArgs e)
{
string proxiesResp = await request("proxy/proxy.php", new Dictionary<string, string> { { "getAllProxyRequests", "" } });
//above returns "count: " in C#, but returns "count: 2" in webbrowser
log(proxiesResp);
}
}
}
Found the problem, it was human error.
I had the file dbconnect.php located one directory below where myProblem.php was located.
I had to change the line saying
include_once 'dbconnect.php';
to
include_once '../dbconnect.php';

Amazon Product Advertising API Signing Issues

i am trying to search in amazon product database with the following code posted in amazon webservice sample codes page
AWSECommerceService ecs = new AWSECommerceService();
// Create ItemSearch wrapper
ItemSearch search = new ItemSearch();
search.AssociateTag = "ABC";
search.AWSAccessKeyId = "XYZ";
// Create a request object
ItemSearchRequest request = new ItemSearchRequest();
// Fill request object with request parameters
request.ResponseGroup = new string[] { "ItemAttributes" };
// Set SearchIndex and Keywords
request.SearchIndex = "All";
request.Keywords = "The Shawshank Redemption";
// Set the request on the search wrapper
search.Request = new ItemSearchRequest[] { request };
try
{
//Send the request and store the response
//in response
ItemSearchResponse response = ecs.ItemSearch(search);
gvRes.DataSource = response.Items;
}
catch (Exception ex)
{
divContent.InnerText = ex.Message;
}
and getting the following error
The request must contain the parameter
Signature.
and amazon documentation is not clear about how to sign the requests.
any idea how to make it work???
thx
i transcribed this vb code and it works for me
add the service reference and name it Amazon
http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl
go into the folder where your project is hosted, open the service reference folder and open the Reference.cs, then replace all the occurrences of [][] with [], next open AWSECommerceService.wsdl and find
<xs:element minOccurs="0" maxOccurs="unbounded" name="ImageSets">
and replace with
<xs:element minOccurs="0" maxOccurs="1" name="ImageSets">
add the following, and you'll need to manually reference some dlls
using System.Security.Cryptography;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Description;
using System.Text.RegularExpressions;
using System.Xml;
using System.IO;
using System.Runtime.Serialization;
using AmazonApiTest.Amazon; //instead of AmazonApiTest use your project name
first various interface implementations
public class AmazonSigningMessageInspector : IClientMessageInspector
{
private string accessKeyId = "";
private string secretKey = "";
public AmazonSigningMessageInspector(string accessKeyId, string secretKey)
{
this.accessKeyId = accessKeyId;
this.secretKey = secretKey;
}
public Object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
{
string operation = Regex.Match(request.Headers.Action, "[^/]+$").ToString();
DateTime now = DateTime.UtcNow;
String timestamp = now.ToString("yyyy-MM-ddTHH:mm:ssZ");
String signMe = operation + timestamp;
Byte[] bytesToSign = Encoding.UTF8.GetBytes(signMe);
Byte[] secretKeyBytes = Encoding.UTF8.GetBytes(secretKey);
HMAC hmacSha256 = new HMACSHA256(secretKeyBytes);
Byte[] hashBytes = hmacSha256.ComputeHash(bytesToSign);
String signature = Convert.ToBase64String(hashBytes);
request.Headers.Add(new AmazonHeader("AWSAccessKeyId", accessKeyId));
request.Headers.Add(new AmazonHeader("Timestamp", timestamp));
request.Headers.Add(new AmazonHeader("Signature", signature));
return null;
}
void IClientMessageInspector.AfterReceiveReply(ref System.ServiceModel.Channels.Message Message, Object correlationState)
{
}
}
public class AmazonSigningEndpointBehavior : IEndpointBehavior
{
private string accessKeyId = "";
private string secretKey = "";
public AmazonSigningEndpointBehavior(string accessKeyId, string secretKey)
{
this.accessKeyId = accessKeyId;
this.secretKey = secretKey;
}
public void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime clientRuntime)
{
clientRuntime.ClientMessageInspectors.Add(new AmazonSigningMessageInspector(accessKeyId, secretKey));
}
public void ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatched)
{
}
public void Validate(ServiceEndpoint serviceEndpoint)
{
}
public void AddBindingParameters(ServiceEndpoint serviceEndpoint, BindingParameterCollection bindingParemeters)
{
}
}
public class AmazonHeader : MessageHeader
{
private string m_name;
private string value;
public AmazonHeader(string name, string value)
{
this.m_name = name;
this.value = value;
}
public override string Name
{
get { return m_name; }
}
public override string Namespace
{
get { return "http://security.amazonaws.com/doc/2007-01-01/"; }
}
protected override void OnWriteHeaderContents(System.Xml.XmlDictionaryWriter writer, MessageVersion messageVersion)
{
writer.WriteString(value);
}
}
now you use the generated code in this way
ItemSearch search = new ItemSearch();
search.AssociateTag = "YOUR ASSOCIATE TAG";
search.AWSAccessKeyId = "YOUR AWS ACCESS KEY ID";
ItemSearchRequest req = new ItemSearchRequest();
req.ResponseGroup = new string[] { "ItemAttributes" };
req.SearchIndex = "Books";
req.Author = "Lansdale";
req.Availability = ItemSearchRequestAvailability.Available;
search.Request = new ItemSearchRequest[]{req};
Amazon.AWSECommerceServicePortTypeClient amzwc = new Amazon.AWSECommerceServicePortTypeClient();
amzwc.ChannelFactory.Endpoint.EndpointBehaviors.Add(new AmazonSigningEndpointBehavior("ACCESS KEY", "SECRET KEY"));
ItemSearchResponse resp = amzwc.ItemSearch(search);
foreach (Item item in resp.Items[0].Item)
Console.WriteLine(item.ItemAttributes.Author[0] + " - " + item.ItemAttributes.Title);
There's a helper class for REST called SignedRequestHelper.
You call it like so:
SignedRequestHelper helper =
new SignedRequestHelper(MY_AWS_ACCESS_KEY_ID, MY_AWS_SECRET_KEY, DESTINATION);
requestUrl = helper.Sign(querystring);
There must be a similar one for SOAP calls in the above links.
try this one.. i hope it'll help.. i try and it works.. please share it with others.
download the sample code on http://www.falconwebtech.com/post/Using-WCF-and-SOAP-to-Send-Amazon-Product-Advertising-API-Signed-Requests
we need to update service references, make little change at app.config, program.cs, and reference.cs.
app.config:
(1.) appSettings tag;
assign accessKeyId and secretKey value,
add .
(2.) behaviours tag -> endpointBehaviors tag -> behaviour tag -> signingBehavior tag;
assign accessKeyId and secretKey value.
(3.) bindings tag -> basicHttpBinding tag; (optional)
delete binding tag except AWSECommerceServiceBindingNoTransport
and AWSECommerceServiceBindingTransport.
(4.) client tag;
delete endpoint tag except AWSECommerceServiceBindingTransport.
program.cs:
add itemSearch.AssociateTag = ConfigurationManager.AppSettings["associateTag"]; before ItemSearchResponse response = amazonClient.ItemSearch(itemSearch);
reference.cs: (open file in service references folder using visual studio)
change private ImageSet[][] imageSetsField; to private ImageSet[] imageSetsField;
change public ImageSet[][] ImageSets {...} to public ImageSet[] ImageSets {...}
finally we can run our program and it will work. good luck..
nb: there will be 1 warning (invalid child element signing behaviour), i think we can ignore it, or if you have any solution please share.. ^^v..

Categories