Writing new data to a service from another program
Hi guys,
Im new to MSRS but have been writing software for robotics in ASM, BASIC, C,C++,C# in the normal way for many years. to get up to speed on MSRS programming Ive been through the service tutorials and the hosting tutorials but unfortunately I am struggling with writing data to the variables inside a service from another program.
Using the dsshosting example program 2 and service tutorial 5, I can see how to read data from a service using commands like "Get" but I dont know what syntax to use in order to alter the data inside the service. I can retreive a class full of data objects which is good, but I dont know how to set those members to different values.
For example I could easily read the value from the increment tick example in my program, but cannot figure out how to use a function like "SetTickCount" to change what that value is. I have not come across a function in a hosting app that does the write operation. Im assuming that it is some sort of Arbiter task with a pair of delegates? There is no example of this sort of operation in the tutorials.
I would think that once Ive got my head around readand write operations in MSRS, I can get on and program robots in the way I always have done.
Please help, as I'd love to use MSRS, its just that from my point of view the tutorials have little holes in them which are hard to fill in.
You can define you own operations within a service that allow you to set the internal state of your service.
Actually, if you look at the handler of the IncrementTick operation you will see that the state in modified (variable TickCount incremented).
Code Snippet
[
ServiceHandler(ServiceHandlerBehavior.Exclusive)] public IEnumerator<ITask> IncrementTickHandler(rst4.IncrementTick incrementTick) {
_state.TickCount++;
incrementTick.ResponsePort.Post(
DefaultUpdateResponseType.Instance); yield break; }
Also, note that you can use a custom class as parameter of your operation (like IncrementTickRequest in this case), therefore, you can define whatever type you need to pass to your service state.
Code Snippet
public class IncrementTick : Update<IncrementTickRequest, PortSet<DefaultUpdateResponseType, Fault>>
{
public IncrementTick()
: base(new IncrementTickRequest())
{
}
}
Pd. I would post this kind of question in the DSS forum (not the community forum).
Thanks for your help but Im not sure if it answers my question.
Please forgive my ignorance but it looks to me like the two code snippets you provided are for operations within the service. This isnt exactly what I mean. What Im trying to do basically is change the value of any old variable inside a service from a hosting program. Im trying to make changes from outside the service.
For example In my hosting program we can use:
Code Snippet
yield return Arbiter.Choice(pServiceTutorial1.Get(),
delegate(st1.ServiceTutorial1State success)
{
// GET Request succeeded
DssEnvironment.LogInfo("Service Tutorial1 state: "
+ success.Member); //<--success.member came out
//of the service
_status = 0;
},
delegate(W3C.Soap.Fault failure)
{
// GET Request failed.
DssEnvironment.LogError("Could not retrieve state.");
}
);
So all that above will give my hosting program the values of all variables in the class named success. - Thats great, but I now want to force new values into the service from my hosting program.
I assumed you could use the same syntax to put something new into the service like:
Code Snippet
yield return Arbiter.Choice(pServiceTutorial1.Replace(),
delegate(st1.ServiceTutorial1State success)
{
success.Member = "this is a test"; // < Im trying to put this into the service
_status = 0;
},
delegate(W3C.Soap.Fault failure)
{
// GET Request failed.
DssEnvironment.LogError("Could not retrieve state.");
}
);
But of course its just giving me a compile time error. I just want to write new values to variables in a service from outside of that service.