I wanted  to consume  a  java webservice, so I wrote a WCF client to consume the service. I thought Java -.Net  interinteroperability would be easy with WCF, not so easy. 

The Java Web Service used WS-Security and required a UserNameToken passed as clear text.  The below code snippet  from Hanselman's blog will solve the problem, but there is a catch . This will work only if the endpoint address is on SSL. Ofcourse, WCF will not allow you to pass UserNameToken ( username & password) as clear text on http. It has to passed on https protocol, only then it will work . 

            

public void WCFMethod()
{

    WSHttpBinding myBinding = new WSHttpBinding();
    myBinding.Security.Mode 
        = SecurityMode.TransportWithMessageCredential;
    myBinding.Security.Message
    .ClientCredentialType = MessageCredentialType.UserName;
    myBinding.Security
    .Message.EstablishSecurityContext = false;

    myBinding.Security
    .Message.NegotiateServiceCredential = false;

    BindingElementCollection elements = myBinding.CreateBindingElements();
    elements
    .Find<SecurityBindingElement>().IncludeTimestamp = false;

    elements
    .Find<TextMessageEncodingBindingElement>()
    .MessageVersion = MessageVersion.Soap11;
    CustomBinding newBinding = new CustomBinding(elements);
    FooPortTypeClient svc = 
    new FooPortTypeClient(newBinding, 
    new EndpointAddress("https://javawebservice.com/service"));
}
 
 

 So, I had to go apply SSL on the webservice, to get this done. I digged more & was wondering if I could create a custom binding by getting my hands dirty. It turned out, there is already an open source custom binding, luckily I stumbled on  Yaron Naveh's  blog. He has writtern Clear Username Binding to solve the problem and is  hosted ongoogle code.  I hope this helps others like me. I used this binding get authenticated on http using WS-Security.

 

I don't know  if people are aware of the below exception. I wanted to throw some light on the issue, and help stranded people solve this issue.
Exception information:
Exception type: ArgumentException
Exception message: '', hexadecimal value 0x01, is an invalid character.

I support a web service which is heavily being used in the company, users who were consuming the web service where reporting problems that it was throwing some exception like above. After lot of investigation I solved the issue with  Bill's blog
Ascii control characters are not allowed in XML, they don't conform to xml specification.  So The .net framework when trying to serialize information with ascii control characters into XML , it throws an exception. These characters should not be allowed.

There are two ways to clean up the data and to remove the characters, you have to search the string , here is how you can do it.

 

/// <summary>
/// Remove illegal XML characters from a string.
/// </summary>
public string SanitizeXmlString(string xml)
{
    if (xml == null)
    {
        throw new ArgumentNullException("xml");
    }

    StringBuilder buffer = new StringBuilder(xml.Length);

    foreach (char c in xml)
    {
        if (IsLegalXmlChar(c))
        {
            buffer.Append(c);
        }
    }

    return buffer.ToString();
}
 
 

source : Bill's blog

 

Here is my version of the code using regex.

 
private string SanitizeXmlString(string xml)
{
 
   if (!string.IsNullOrEmpty(xml))
   {
     char[] hexp = new char[7] 
     { '\x00', '\x08', '\x10', '\x19', 
       '\x0B', '\x0F', '\x7F' };
     string pattern = string.Empty;
     pattern = string.Format("[{0}-{1}{2}-{3}{4}-{5}{6}]", 
     hexp[0], hexp[1], hexp[2], 
     hexp[3], hexp[4], hexp[5], hexp[6]);
     xml = Regex.Replace(xml, pattern, "");
    }
   
    return xml;  
}

 

 

Book Review : Career 2.0 take control of your life

I stumbled across some blog via twitter and read an article about the book.  I had never heard of Jared Richardson before.

I watched career 2.0 video recorded at the Minnesota  code camp. I decided to buy the book and read it. Career 2.0  book delivers what it promises. The book was in the market at the right time for developers. The book targets technical people, clearly motivates you to learn, talk and emphasis and shows you should invest in your career.

Notes from the book :

"You're not a victim of anyone but yourself"

    The book first explains why is it that you should invest in your career. It brings out some good examples from the telecom bust. The technology has a shelf-life of a banana, New languages and frameworks are spawning out each day. Start learning the technology of the year (LOTY) or a new language each year.

The author refers to  the "Pragmatic Programmer" about learning a new language each year.  He compares learning new language to running or picking up a new or old sport that you never played or left playing a  long time.

Goals

"Mt Everest and you".

This book lays out options and strategies on how to go about making the start. Plan, prepare and climb. We spend most of your awake hours at work. How can we prioritize, learn and achieve our goals. The author explains the Maslow's Pyramid ( hierarchy of needs) with 5 levels, when you should focus on creativity and growth, definitely not when you don't have a job. Climb the pyramid to acheive your goals. The author keeps his language really simple , easy to read and it helps assimilate the wealth of the book immediately.


Share & learn:

  "Your knowledge grows as you give ". 


Start a blog, document what you learn each day. Read a book and review it in your blog. This would help the learning process also improve your writing skills, if it sucked badly like mine.

Present a topic that you learnt at a users group, workplace or a code camp. Jared puts these different ideas with anecdotes, which shows the benefits really well.

With the power of Search Engines, your blog could help someone in some country. Write a page everyday, about something, that would improve your writing.

Verdict:

The book is a must buy for all technical folks who would want to grow and climb the ladder. This book is a real motivator, when can you say that ? when you immediately get of your couch and do what the book says.

There is an interesting tale behind this, I first saw a computer in the early 1990's at my school. My youger sister was learning LOGO at school. I took her book and read through in summer. The next year I started learning Basica at school in my 8th grade. My fascination grow when i saw somebody play Prince of Persia game on a 486 PC. I went onto study Computer Science in College . I started learning algorithms and programmed in FORTRAN 77 and PASCAL.

I still remember my programming assignment which exposed me to a different language called Scheme. I could see the power of recursion in action. We had to convert a 600 line c code to scheme. The scheme code turned out to be only 100 lines. I learnt Visual basic 6.0 in college, which taught my how to build data driven application. This helped land ino my first real job which was developing a contact management system in Visual Basic 6 and MS Access. From there I went on learning web programming and developed applications in classic ASP and moved to .NET.

Its been 2 weeks after the InfusionDev Sleepless in L.A  event. It's time to talk about it.  I really enjoyed the all night coding challenge on sharepoint. There were just two people from Northern California for the event. I was suprised to know from Kurt that only 4 people were registered for the event.  I liked all the presentations of Kurt and Shawn. I wish they gave some training. I was expecting to gain some insight on Business Data catalog (BDC). It was there on Kurt's slides and he never had time to talk about it. 

The evening was fun, the event was sponsored by Microsoft. We had a ride on a Limo ( partied like a rock star).   I was in a team of two. We were short of one person. We decided to get something implemented soon and hit the bed. So Paras and I  wrote a Photo Slide show Web part using Flicker.Net Api from Codeplex. The idea was to contribute something to community kit for sharepoint in codeplex.  We had an arguement whether to try silverlight with sharepoint or not.  We did not win. The judges were looking for some sharepoint features like list, document library. Unfortunately, we did not leverage it. Kesav's Team won the prize. They deserved it for their idea and implementation. 

Here are some pictures from the event.

such a big hummer Limo.

Big Hummer

source: infusion sleeless

I should be hiding somewhere in the back on the right side.

with the Crew

 source: infusion sleeless