Sending service actions with PostFileWithRequest

The PostFileWithRequest operates differently to the normal Post request in that instead of sending a simple JSON object it sends a multi-part form request with the object (e.g. a Record) serialized not to JSON but as an HTML form.  This means that some complex constructs, such as the Record.AccessControlList, do not translate well.


Service Actions, sent in ActionsToCall, nearly work except for the code that specifies the type of Service Action.  The good news is that this can be tweaked on the client side by overriding the code to emit the type name.  In the sample below the line JsConfig.TypeWriter... called after TrimClient is instantiated, should allow any Service Action to be de-serialized by the ServiceAPI.

TrimClient trimClient = new TrimClient("http://MyServer/ServiceAPI");
trimClient.AlwaysSendBasicAuthHeader = true;
trimClient.UserName = "USERNAME";
trimClient.Password = "PASSWORD";

JsConfig.TypeWriter = (tt) => {
    return string.Format("{0}.{1}", tt.Namespace, tt.Name);
Record rec = new Record();
rec.RecordType = new RecordTypeRef() { FindBy = "Document" };
rec.Title = "test";
rec.ActionsToCall = new List<IMainObjectActionRequest>();

rec.ActionsToCall.Add(new AttachContact()
    AsContactType = ContactType.Addressee,
    ContactLocation = new LocationRef() { FindBy = "Me" }

rec.ActionsToCall.Add(new AttachContact()
    AsContactType = ContactType.Other,
    ContactLocation = new LocationRef() { Uri = 9000000072 }

FileInfo fi = new FileInfo("c:\\junk\\Test.txt");

var response = trimClient.PostFileWithRequest<RecordsResponse>(fi, rec);