by Mike.Sheen » Fri Jun 30, 2017 1:09 pm
Hi Stuart,
You can remove them at any time, and the next call won't include them.
Here's an example from our unit tests which use the ServiceStack client to do exactly that:
- Code: Select all
[Test]
public void Carriers_Stateful_Create_Save()
{
client.Headers.Add("jiwa-stateful", "true");
// Try before logging on to make sure we get a 401
var carrierPOSTRequest = new CarrierPOSTRequest { CarrierName = Guid.NewGuid().ToString(), Enabled = false };
Carrier carriersPOSTResponse;
var ex = Assert.Throws<ServiceStack.WebServiceException>(() => carriersPOSTResponse = client.Post(carrierPOSTRequest));
Assert.AreEqual(401, ex.StatusCode);
Logon();
// POST: /Carriers
carrierPOSTRequest = new CarrierPOSTRequest { CarrierName = Guid.NewGuid().ToString(), Enabled = false };
carriersPOSTResponse = client.Post(carrierPOSTRequest);
// Check the response has the same name as the request
Assert.AreEqual(carriersPOSTResponse.CarrierName, carrierPOSTRequest.CarrierName);
// Now do a non-stateful read to make sure it's not present yet
// GET: /Carriers/{CarrierID}
client.Headers.Remove("jiwa-stateful");
var carrierGETRequest = new CarrierGETRequest() { CarrierID = carriersPOSTResponse.CarrierID };
// We expect a 404 when reading
Carrier carrierGETResponse;
ex = Assert.Throws<ServiceStack.WebServiceException>(() => carrierGETResponse = client.Get(carrierGETRequest));
Assert.AreEqual(404, ex.StatusCode);
// Add back the stateful header
client.Headers.Add("jiwa-stateful", "true");
// GET: /Carriers/{CarrierID}/Save
var carrierSAVERequest = new CarrierSAVERequest() { CarrierID = carriersPOSTResponse.CarrierID };
var carrierSAVEResponse = client.Get(carrierSAVERequest);
// GET: /Carriers/{CarrierID}
carrierGETRequest = new CarrierGETRequest() { CarrierID = carrierSAVEResponse.CarrierID };
carrierGETResponse = client.Get(carrierGETRequest);
// Check the Name is what we expect
Assert.AreEqual(carrierGETResponse.CarrierName, carrierPOSTRequest.CarrierName);
}
EDIT: To answer your question, the ServiceStack client will include them for every request once set, until removed.
Mike Sheen
Chief Software Engineer
Jiwa Financials
If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution