While brushing my teeth last night, I put my finger on it.
I had two requests from the Panda. One was working fine, and one request blew up (e.g. the http client code in the panda blows up, this is the client:
http://code.tinyclr.com/project/288/http-client-sample-code-for-fez-connect/ )
I had first focused on headers, content-length, and actual content. (I have a lot of experience with this stuff, outside the microcontroller world). But I got the working response to mirror the problem response in ALL those ways… and still one worked, and one did not.
(I used fiddler to carefully compare the raw responses from the working and non working requests)
Brushing my teeth, I realized there is still a delta: Response time. The working responses were in the 100-250 msec response time range, but the nonworking responses were 300+ msec, usually 500msec to 2000 msec.
(This is material, because the panda is calling a web service that needs time to get its data and do some work… So my “good” calls from panda [that fetch data] fail, and my “bad” calls from panda [that result in a quick error message from the REST server] work.)
So this AM I worked on it (I normally only work on this in evening, as this is a hobby project, not my day job). And YES, response time from the server is THE issue.
The server Panda is hitting is a very simple, .NET REST server based on WCF, .NET v4.
Here is the way to see the issue:
>>>>>>>>>>>>>>>>>>>>
// This is the block in the REST server that returns data to the client...
if (ValidStringMask & Validparameter1Param & Validparameter2Param & Validparameter3Param)
{
// Params are valid, so Go Get Some Data!!
// FAILS from Panda http client, because takes 500-2000 msec
return
new MemoryStream(Encoding.UTF8.GetBytes(myfuncs.BuildStringFromList(MyDataList)));
}
else
{
// GHI-Itis is this next line!
// Remove it, and the http client on panda works fine, gets payload.
// Put it in... and the http client on panda fails to handle response....
System.Threading.Thread.Sleep(300);
return new MemoryStream(Encoding.ASCII.GetBytes("Invalid parameters provided"));
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
The main body of the rest server is this, includes the above:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.IO;
using myfuncs = MyNewFuncs.myfunctionlib;
using MyNewFuncs; // this seems redundant to above, because namespace is not well organized...
namespace REST1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
public Stream GetDataFromWebSite(string returnstringmask, string parameter1, string parameter2, string parameter3)
{
// test that we received useful input params
bool Validparameter1Param = false;
bool Validparameter2Param = false;
bool Validparameter3Param = false;
bool ValidStringMask = false;
Int16 TargetInt = 0;
if (returnstringmask.Length == 8)
{
ValidStringMask = true;
}
Validparameter1Param = (Int16.TryParse(parameter1, out TargetInt));
Validparameter2Param = (Int16.TryParse(parameter2, out TargetInt));
Validparameter3Param = (Int16.TryParse(parameter3, out TargetInt));
// Attempting to get the GHI http lib to work... this was a dead end, but is the right thing to do...
WebOperationContext.Current.OutgoingResponse.ContentType = "text/html; charset=utf-8";
if (ValidStringMask & Validparameter1Param & Validparameter2Param & Validparameter3Param)
{
// Params are valid, so Go Get Some Data!!
// FAILS from Panda http client, because takes 500-2000 msec
return
new MemoryStream(Encoding.UTF8.GetBytes(myfuncs.BuildStringFromList(MyDataList)));
}
else
{
// GHI-Itis is this next line!
// Remove it, and the http client on panda works fine, gets payload.
// Put it in... and the http client on panda fails to handle response....
System.Threading.Thread.Sleep(300);
return new MemoryStream(Encoding.ASCII.GetBytes("Invalid parameters provided"));
}
}
}
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<