I am making a call to a REST web service and the mobile app is retrieving the results from its cache and not going to the server.
I have seen other suggested fixes (similar issue and similar issue2) but the Cache property is not available in silverlight 4.
Does anyone have an idea of how to force silverlight 4 on windows phone 7 to make a request and not hit the cache?
Although not ideal, a easy solution is to send something like the field "junk" with the value DateTime.Now. That way, a value is always brand new, and will never get cached. If you were doing this in a standard querysting for example:
"&junk=" + DateTime.Now;
I've hit this problem too on overflow 7 talking to StackApps - the only thing I could think of was to add an addition random variable to the end of the HTTP/REST request.
The most proposed solution is the same as William Melani's.
But it is not ideal and some services reject requests with unknown parameters or any parameter. In this case it is cleaner and more reliable to use the IfModifiedSince header as follows:
WebClient wc = new WebClient();
wc.Headers[HttpRequestHeader.IfModifiedSince] = DateTime.UtcNow.ToString();
wc.DownloadStringCompleted += wc_DownloadStringCompleted;
wc.DownloadStringAsync(new Uri(bitstampUrl));
WebClient wc = new WebClient();
wc.Headers[HttpRequestHeader.IfModifiedSince] = DateTime.UtcNow.ToString();
worked for me
Related
While I'm aware that MVC6 isn't released, it looks like it's missing many features of WebAPI and even MVC5. Can I assume that this isn't the way that it'll look on release?
[HttpPost("")]
public async Task<ActionResult> Post(Visit newVisit)
{
var username = User.Identity.GetUserName();
newVisit.UserName = username;
if (await _repository.AddVisitAsync(newVisit))
{
Response.StatusCode = (int) HttpStatusCode.Created;
return Json(newVisit);
}
return new HttpStatusCodeResult((int)HttpStatusCode.BadRequest);
}
Notice the casts in the Reponse.StatusCode and the HttpStatusCodeResult (I do miss just returning Ok(...), Created(...), etc.
Some features from MVC 5 and Web API 2 have not yet been brought over to MVC 6 (which includes Web API). Logging issues at https://github.com/aspnet/Mvc/issues is the right place to request any missing features. Please check for existing issues because many issues are already tracked.
Please note that several APIs got renamed when MVC and Web API got merged because we didn't want to have duplicate APIs, so even though an exact API match might not be there, it could just have a new name.
I am working on a .NET MVC3 C# Application. This application is hosted on our own Server.
Now I want to Send Scheduled Email in my application like daily(at a specific time),Weekly, monthly and so on...
Currently I am using MVCMailer to send Emails in my application.
I tried Fluent Scheduler to send scheduled Emails, but it doesn't works with MVCMailer. It Works fine if I send mails without MVCMailer and for other scheduling jobs.
It gives me a ERROR NULLReferenceException and says HTTPContext cannot be null.
What can I do to solve this problem.
Also suggest me which will be the best way to send E-mails in my applicaton.
Windows Service (Having own server)
Scheduler (Fluent Scheduler)
SQL Scheduled jobs
I am attaching ERROR snapshot:
It could be that MVCMailer depends on an HttpContext, which will not exist on your scheduled threadlocal's.
You could consider scrapping MvcMailer and implementing your own templating solution. Something like RazorEngine (https://github.com/Antaris/RazorEngine), which gives you the full power of Razor without having to run ontop on an Http stack. You could still source your templates from disk so that your designers could modify it.
Then you could mail the results using the standard classes available from .net.
For e.g.:
string template = File.ReadAllText(fileLocation);//"Hello #Model.Name, welcome to RazorEngine!";
string emailBody = Razor.Parse(template, new { Name = "World" });
SmtpClient client = new SmtpClient();
client.Host = "mail.yourserver.com";
MailMessage mm = new MailMessage();
mm.Sender = new MailAddress("foo#bar.com", "Foo Bar");
mm.From = new MailAddress("foo#bar.com", "Foo Bar");
mm.To.Add = new MailAddress("foo#bar.com", "Foo Bar");
mm.Subject = "Test";
mm.Body = emailBody;
mm.IsBodyHtml = true;
client.Send(mm);
Obviously you could clean this all up. But it wouldn't take to much effort to use the above code and create some reusable classes. :)
Since you already have the FluentScheduler code set up, you may as well stick with that I guess. A windows service does also sound appealing, however I think that it's your call to make. If it's a simple mail service you are after I can't think of any reason not to do it via FluentScheduler.
I have created a full example of this available here: https://bitbucket.org/acleancoder/razorengine-email-example/src/dfee804d526ef3cd17fb448970fbbe33f4e4bb79?at=default
You can download the website to run locally here: https://bitbucket.org/acleancoder/razorengine-email-example/downloads
Just make sure to change the Default.aspx.cs file to have your correct mail server details.
Hope this helps.
Since MVC Mailer works best in the HTTP stack (i.e. from controllers), I've found that a very reliable way to accomplish this is by using Windows Task Schedule from a server somewhere. You could even spin up a micro instance on Amazon Web Server.
Use "curl" to call the URL of your controller that does the work and sends the emails.
Just setup a Scheduled Task (or Cron if you want to use *IX) to call "c:\path_to_curl\curl.exe http://yourserver.com/your_controller/your_action".
You could even spin up a *IX server on AWS to make it even cheaper.
Netflix recently updated their API methods for obtaining the full Netflix catalog. I'm curious if anyone has had any success accessing these new xml documents and downloading them via API v1.5 (9/2012). Previously, you could download the entire Netflix catalog via one API call (which I had working perfectly). Now, there are supposedly two calls to make: one for dvd's and one for streaming movies.
I cannot make these calls return anything except for an empty array. Please don't offer an answer unless you have personally downloaded the entire catalog via these new API's.
Bonus points if you can tell me how to do it in Ruby.
http://developer.netflix.com/blog/read/Update_Changes_for_the_Public_API
This did it for me (download the netflix instant cat)...it's in php but can prob be easily rewritten in ruby..this is using JR Collings OAuthsimple
args = Array(
max_results=> 20,
start_index=>0
);
//args don't matter, netflix doesn't listen here
// this is the URL path (note the lack of arguments.)
$rpath = "http://api-public.netflix.com/catalog/titles/streaming";
// Create the Signature object.
$roauth = new OAuthSimple();
$rsigned = $roauth->sign(Array(path=>$rpath,
parameters=>$args,
signatures=> Array('consumer_key'=>YOURKEY,
'shared_secret'=>YOURSECRET,
)));
$getxml = file_get_contents($rsigned['signed_url']);
file_put_contents("streaming.xml", $getxml);
I'm new to Windows phone 7 application development. I'm currently developing an app in which I wish to do a HTML request and display the result obtained in Web browser. For example, Suppose I give the below URI
"http://m.imdb.com/find?q="+search_string (where search_string is a variable)
I want to take the result obtained from this and display it on the web browser. I've been searching regarding this for past 1 day... Didn't get any fruitful results. So please redirect me either to a suitable tutorial page or please give a sample code?
WebBrowserTask wbt = new WebBrowserTask();
wbt.URL = "http://m.imdb.com/find?q="+search_string
wbt.Show();
this will allow you to launch the url in the browser.
WebBrowserTask
I'm creating a Windows Phone 7 app which allow to listen a web radio. But I also want to get the cover of the song and I want it to be refreshed every 3 minutes for example.
When I start debugging my app, I've no problem but I've no idea how to call back my code to refresh the cover.
Thanks a lot.
Aymeric.
I found a solution not really the one I looked for but my mates used a timer to refresh the same application for Android and iOS since there is no push notification from the server.
So I used this code
DispatcherTimer refreshTimer = new DispatcherTimer();
refreshTimer.Interval = TimeSpan.FromSeconds(30);
refreshTimer.Tick += new EventHandler(refreshTimer_Tick);
refreshTimer.Start();
Thank you all for the time you spent on this question.
Aymeric.