Reputation: 3305
I have a web service
and I am going to access the database
over that web service. I am going to save a text file to my DB using web service.
Before saving file to the DB I want to make sure that that the file not changed.
I have no idea to how to do this. Can please anybody explain me how to do this. Specifying the steps would be enough.
EDIT
I am passing my text file to the web service as byte array
. In other words I want to make sure all the bytes which I sent, has received to the web service as it is.(not corrupted nor loose of data). I have control over the web service as well.
Upvotes: 1
Views: 644
Reputation: 2766
You generally don't need to check that, you have different communication layers that do that for you.
If a package is lost during transport, it will be resent, and if damaged, will be corrected/sent again. assuming you are using TCP/IP protocol , your transport layer guarantees that data will transfer properly, without you having to deal with it.
(this is a file and not a streaming video, UDP protocol will have possible corruption of data, which is ok in video/audio)
*Just to clear things up: you are at the application layer.
Edit:
From Wikipedia regarding TCP/IP:
This abstraction also allows upper layers to provide services that the lower layers do not provide. While the original OSI model was extended to include connectionless services (OSIRM CL),[16] IP is not designed to be reliable and is a best effort delivery protocol. This means that all transport layer implementations must choose whether or how to provide reliability. UDP provides data integrity via a checksum but does not guarantee delivery; TCP provides both data integrity and delivery guarantee by retransmitting until the receiver acknowledges the reception of the packet.
Upvotes: 1
Reputation: 1164
You should calculate checksum of file, to validate it on client.
string checkSum=null;
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create()) {
checkSum= BitConverter.ToString(
md5.ComputeHash(Encoding.UTF8.GetBytes(theString))
).Replace("-", String.Empty);
}
Upvotes: 1