Tuesday, February 13, 2007


One more note before closing tonight, if your not using Coderush or Refactor Pro!, get it now!!!
These two combined will make your daily coding so much faster. I use these everyday and when I work on someones box that doesnt have them, I feel like I have a handycap. Mark Miller is the creator of this magnificant product formerly Eagle Software which I believe he now works for DevExpress which owns the product today. Either way, get to DevExpress.com and purchase this fantastic product as it will make your coding fly...

Nice one Jason

After reading Jasons blog at http://jasonf-blog.blogspot.com I came across an interesting article to myself being a former WoW player as well as Star Craft (Brood War). This type of mistake probably cost someone their job.


Serial Port Usage

I had a project assigned to me reading information from a scanner and taking the information retrieved and converting the bytes to base64 and passing the base64 to a decoder which could take a USPS barcode in PDF-417 or DataMatrix and parse out its information into human readable information of all information contained within the barcode using an IBI Dictionary. I cannot demonstrate all parts of the project but I would like to demonstrate gathering information from a port and converting it to base64. This is rather simple and probably elementary for most developers.

First of all, you must create a serial port like so:

SerialPort port = null;

On Load of Form, or constructor do the following:

port = new SerialPort(Port, 9600, Parity.None, 8, StopBits.One);
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);

string Base64Scan = string.Empty;
void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
byte[] buffer = new byte[port.BytesToRead];
port.Read(buffer, 0, port.BytesToRead);

// Convert to Base64
Base64Scan = Convert.ToBase64String(buffer);

This is it, now some would say why even bother with such a simple blog. The reason, I ran into a problem in the first phase of reading the information into a string using
port.ReadExisting(); which caused a problem because the .NET encodation caused the results to be wrong. When char 255 or FF was recieved, it was converted to char 63 or 3F. By reading the bytes directly, the correct results were returned. Hopefully this will help others that fall into this problem.

Monday, February 05, 2007

Here is a snippet I put together on using UserName token with Web Services3.

MyWebService myService = new MyWebService();
// Create the policy
Microsoft.Web.Services3.Design.Policy policy = new Microsoft.Web.Services3.Design.Policy();
policy.Assertions.Add(new Microsoft.Web.Services3.Design.UsernameOverTransportAssertion());
myService .SetPolicy(policy);
myService.Url = http://whatever the url is;
UsernameToken token = new UsernameToken(username, password, PasswordOption.SendPlainText);
ISecurityTokenManager securityTokenManager = SecurityTokenManager.GetSecurityTokenManagerByTokenType(WSTrust.TokenTypes.UsernameToken);
// If your service needs Credentials for connection pass something like this
if (CredentialUserName.Length > 0)
System.Net.NetworkCredential cred = null;
// User Credentials
if (CredentialDomain.Trim().Length == 0)
cred = new System.Net.NetworkCredential(CredentialUserName, CredentialPassword);
cred = new System.Net.NetworkCredential(CredentialUserName, CredentialPassword, CredentialDomain);
System.Net.CredentialCache credCache = new System.Net.CredentialCache();
credCache.Add(new Uri(myService.Url), "Basic", cred);
if (CredentialDomain.Trim().Length > 0)
credCache.Add(new Uri(myService.Url), "Digest", cred);
credCache.Add(new Uri(myService.Url), "Negotiate", cred);
myService.Credentials = credCache;
// Now do your stuff

Creative Commons License
Blogged Information and Code is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.