Creating a Unique ID

I am looking for advice or solution for creating a Unique ID. Basically I need to record a transaction id whenever my SOAP applications shake hands and I was unsure as to the best solution.

Previously I had just used an int, and bumped it up every time the handshake was made, but perhaps there is a better method like GUID?

Anyone got any ideas, or examples
directxBOBAsked:
Who is Participating?
 
McExpCommented:
You got it in one a GUID is waht you want!

Guid.NewGuid().ToString();
0
 
Dorfer32Commented:
GUIDs are wonderful, and C# makes generating new ones easy:

Guid id = Guid.NewGuid();

With things like ints you may run into issues where multiple clients counters are not synchronized or restarting the client restarts the counter which causes values to reuse.  Using GUIDs avoids these issues as the generation routine is random not sequential, so it is extremely unlikely you would ever get a duplicate id.
0
 
directxBOBAuthor Commented:
So there is no requirement to track what ID was last used because they are random?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
McExpCommented:
Yes, that is correct
0
 
directxBOBAuthor Commented:
Also given that a GUID is a 128bit integer I assume I can cast it to an int for general usage?
0
 
McExpCommented:
Guess so, It's not something I've ever had cause to do.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.