Wednesday, December 12, 2012

Exposing WCF Service wsHttpBinding to SoapUI

Testing a WCF Service with wsHttpBinding in SoapUI gives you the following error:
The message could not be processed. This is most likely because the action ‘[Insert Web Service Action Here]’ is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint’s binding.

SoapUI doesn't support security context tokens. Add these lines in Web.config:

  
    
      
        
          
          
        
      
    
  


Make sure that SoapUI has WS-Addressing set to true.

Thursday, September 20, 2012

C# Builder Pattern

So I have been learning C# lately and trying to apply some concepts from Joshua Bloch's Effective Java 2.

The builder pattern.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PaymentLibrary
{
    public sealed class CardType
    {
        public string Id { get; private set; }
        public string Name { get; private set; }
        public string IssueFlag { get; private set; }
        public IList<int> Lengths { get; private set; }
        public IList<string> Prefixes { get; private set; }

        private CardType()
        {
        }

        public sealed class Builder
        {
            private string id;
            private string name;
            private string issueFlag;
            private IList<int> lengths = new List<int>();
            private IList<string> prefixes = new List<string>();

            public Builder WithId(string id)
            {
                this.id = id;
                return this;
            }

            public Builder WithName(string name)
            {
                this.name = name;
                return this;
            }

            public Builder WithLength(int length)
            {
                this.lengths.Add(length);
                return this;
            }

            public Builder WithIssueFlag(string issueFlag)
            {
                this.issueFlag = issueFlag;
                return this;
            }

            public Builder WithPrefix(string prefix)
            {
                this.prefixes.Add(prefix);
                return this;
            }

            public CardType Build()
            {
                CardType cardType = new CardType();
                cardType.Id = id;
                cardType.Name = name;
                cardType.IssueFlag = issueFlag;
                cardType.Lengths = lengths;
                cardType.Prefixes = prefixes;
                return cardType;
            }
        }
    }
}

Usage:
CardType cardType = new CardType.Builder()
                                    .WithId("MC")
                                    .WithName("Mastercard")
                                    .WithIssueFlag("N")
                                    .WithPrefix("49")
                                    .WithPrefix("56")
                                    .WithLength(16)
                                    .WithLength(18)
                                    .WithLength(19)
                                    .Build();

Wednesday, July 25, 2012

Brain as the tool of the spirit

The mind as the bridge between pure consciousness and the body in which that consciousness temporarily resides.


Thursday, June 21, 2012

Friday, April 27, 2012

DNS Lookup in Java

A simple DNS lookup in Java
import java.net.InetAddress;
import java.net.UnknownHostException;

public class DNSLookup {
    
    public static void main(String... args) {
        InetAddress inet = null;
        try {
            final String host = "eradicus.blogspot.com";
            inet = InetAddress.getByName(host);
            System.out.println("DNS Lookup: " + host);
            System.out.println("IP Adress: " + inet.getHostAddress());
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
By using the InetAddress API you will be able to obtain the IP address of the target.

Thursday, April 26, 2012

Reversing a linked list in C++

Linked list is one of the most popular data structures in Computer Science. Read more about linked lists [here]. In this entry we will write a function to reverse a linked list in C++ efficiently.
Link* reverse_list(Link* p)
{
    if (p == NULL)
    {
        return NULL;
    }

    Link* h = p;
    p = p->next;
    h->next = NULL;

    while(p != NULL)
    {
        Link* t = p->next;
        p->next = h;
        h = p;
        p = t;
    }

    return h;
}
Enjoy.