Domanda

What is the best way of exchanging data between a C# desktop application and WCF service? The only method I know now is to send data as a string array with delimiters.

Thanks

È stato utile?

Soluzione

What kind of data do you want to send to the WCF service, and can you alter both the client and the service?

For binary data you could best use an net.tcp-binding, which is optimal for that kind of data and has the least overhead.

If you simply need to send multiple variables in one call, you can decorate a class that contains properties for every variable you want to send with a data contract and send that object as a whole, without the need to use delimiters you use when all data is in one variable.

Altri suggerimenti

It depends on what data you want to send.

Simple data - single valued - should be sent using the appropriate type such as an integer.

More complex data should be put in an object. It's a good idea to use DTOs, which are objects with no behaviour.

Your WCF project should define the relevant class, and any client of the service (your desktop app) will then have access to the class.

This is far easier for the client to use than a string array. To take just one example, your client would have to know the right location in the string array before setting a value. With DTOs it is simply a case of, for example, customer.ModifiedDate = DateTime.Now;

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top