If you’re building a service Host
who will exchange messages with your clients
, the ideal would be to use as a basis the standards already established for this type of operation, such as XML
or JSON
, you might think about leveraging the resources of the framework and providing that interaction as a SOAP
, WCF
or a Web API REST
Not that it’s impossible to implement the way you put it, but instead substring()
I would make a split()
for |
to split arguments. Making this a rule of your contract model.
{string} | {string message}
var mensagem = data.split('|');
if(mensagem[0] == "a2") //E demais validações
{
var result = mensagem[1];
}
As it stands, you’ll soon face problems in case you have to answer a code "a10"
or if you need to increase the set of information sent or received as parameters other than code and message. This practice will still bring you more problems if you intend to distribute your service to third parties to make their own implementations to consume it.