If you are building a Host
service that will exchange messages with your clients
, you should ideally use the already established standards for this type of operation, such as XML
or JSON
, you might think to take advantage of the features of the framework and provide this interaction as a SOAP
, WCF
or a Web API REST
Not that it's impossible to implement the way you presented it, but instead of substring()
I'd make a split()
by |
to split the arguments. Making this a rule of your contract template.
{string code} | {string message}
var mensagem = data.split('|');
if(mensagem[0] == "a2") //E demais validações
{
var result = mensagem[1];
}
As you are, you will soon have problems if you have to respond to a "a10"
code or if you need to increase the set of information sent or received as other parameters besides the code and message. This practice will still bring you more problems if you plan to deploy your service so that third parties can make their own implementations to consume it.