Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Wednesday, September 21, 2011

GSPMigrator source code release

After leaving the source codes for this tool, i've decided to put it on CodePlex with the GNU v2 licence, hoping that it will support and help any one that needs to migrate files into SharePoint 2007 (and in the future 2010).

GSPMigrator is basically a migration tool that allows anyone within the network to connect to a network drive and view it with a tree view.



There are several problems (although there are still some minor ones) that i went through before coming out with this version:

  • Lazy-loading vs eager-loading on generating tree views
Lazy-loading will give better user experience.

Tuesday, October 12, 2010

WSE 3.0 & inversed murphy's law

I know that murphy's law exist and in short, it's a law that states that whatever might go wrong, will go wrong.

But I was forced to do OT to implement WSE 3.0, a technology that went out of support(?) since 2005? I started the implementation with a I'm-gonna-OT-till-client-gets-pissed attitude. But at the last min after struggling for 2hrs with an exception, "The security token cannot be authenticated or authorized."

I managed to rectify it... A stroke of genius came when I try to use command prompt to run notepad as the user specified in the security contract.. Command prompt returned me: user account is being locked out.


True enough everything went OK after I unlocked the account via "local users and group" -__-

The command:
"runas /user: notepad.exe"

For once.. Murphy's law worked for me instead of against me.

Wednesday, July 28, 2010

WSE 3.0 extreme latency

We had a legacy .NET web-service that uses WSE 3.0. We are the service provider and we have an intermediate authentication server as well as the consumer. We had intermittent mysterious socket time out exceptions.

A thorough network snoop was conducted across 4 network teams (we span across 2 intranet and 2 WAN domains). Everything was healthy with <10ms latency between hops.

It was puzzling and a stroke of genius came by and we decided to check the inputtrace.webinfo and outputtrace.webinfo (default logging configs). Nothing special about it except for the size. Monthly scheduled jobs archival results in file size in excess of 600mb. Some team members had argued that logging mechanism should be asynchronous and should not have any influence on the response SOAP. There's no harm trying to flush out the logs and archive and do a re-test. Sure enough everything was back to < 0.5s

Our corrective action was to increase the frequency of the archival from monthly to weekly.

Thursday, April 22, 2010

Encrypting values in web.config

Sometimes user requirements don't allow you to put password or sensitive data in web.config.

There is a really simple to do it:


  1. go to "command prompt"
  2. type: cd "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\" (which every your drivespace is)
  3. type: aspnet_regiis.exe -pef "<Name of node to encrypt>" "<Full path to web.config>"

Your done.



Edit post:

It was really that simple when i do it on my development server. But when i do the same thing on the SIT server, i was thrown with: "The RSA key container could not be opened"


Solution for me:

  1. Ensure that you have permission to use the keys in "C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys" 
  2. Check the keyContainerName in "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config"
  3. go to "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727" type aspnet_regiis -pa "NetFrameworkConfigurationKey" "NT AUTHORITY/NETWORK SERVICE"
I'm assuming you are using the default name for NetFrameworkConfigurationKey.


Then go to the top of the post to do the encryption again.

Good luck.

Tuesday, April 20, 2010

Resizing array

If you ever had to work with an array that you wouldn't know the size till run-time, you have a couple of options:


  1. Clone the old array into the new array (un-necessary overhead)
  2. Just proceed with a array with redundant trailing allocated memory
  3. You can resize it with Array.Resize(ref <arrayName>, int newArraySize)


int[] myArray = new int[50];
int newArrayCount = 0;

//some biz logic goes here
//determined array size

newArrayCount = myArray.Count;

Array.Resize(ref myArray, newArrayCount);

You can put myArray.Count as the 2nd parameter of the resizing method, up to your preference.

Sunday, April 11, 2010

c#: boolean vs bool, String vs string, Int32 vs int

A frequently asked question, what is the difference between a Boolean and a bool object in c#? In short, it's actually the same thing. When compiled to MSIL(Microsoft Intermediate Language), they are referring to System.Boolean, thus there's no implication in performance.

But as a good conventional practice, i always use bool & string as opposed to Boolean & String. Unless you always use System.Int32 instead of int.

Friday, April 9, 2010

IIS logs 400 0 64

From my previous post, i've described how to consume a .NET webservice using netbeans. However, due to the JDK version on my colleague's solaris server, they are not able to import several libraries in order to do so.

Thus, they had use socket programming to send out the SOAP request. Everything was doing fine and well on development server, SIT server, and our local machines.

The wierd thing happens when the swing-over to UAT. When the function was called to send the SOAP request and in the while loop that waits for server response, it kept waiting... waiting... waiting... After several attempts to find faults in the java, web service and JDK versions. There was still no good explanation nor solutions. I went onto the web service machine and dug up the IIS Logs and found a couple of lines that showed the request reaching the web service machine but with an error code 400 0 64. After some research, i found out that the error code represents Bad request. Another vague error message -_-.

I almost wanted to give up, until i went into the HTTPERR folder and open up the logs and saw something that caught my attention. There was a request coming into the server via port 9090, but the response was sent to a random port number.

Bingo! In my client's environment, firewalls will block all the traffic going into the servers unless the need arises and we have to write in service requests to open up the port.

1 more problem resolved and hope this post will help anyone that hit this error.

Monday, April 5, 2010

Consume .NET webservice with only WSDL file

Objective: Consume .NET web service
Problem: I only have WSDL file (Server is blocked from my dev server)

In the past, a web service consumption was only: Right click on project, click on "Add web reference" and enter URL. But it's different this time as the production server had firewalls that blocked unauthorized/unnecessary access. I know it's possible to generate class files from the WSDL file, but how?

Time saver:.NET Framework Tools

After you generate the .cs file, CSC compile it into a dll and put the dll into your project and you will be able to invoke web methods immediately. For my case, i have to bring it to the production server to try access it, and it did worked perfectly :)

Sunday, April 4, 2010

Performance bottleneck? review boxing & unboxing frequencies

There are times where our applications exceed users' response time threshold of 7s (usually), where all action must be completed under 7s.

Page-by-page code reviews are the last resort, but when you are resorting to that, look out of redundant boxing and unboxing of objects, check out: Technet

That's usually my case, or un-necessary objects declaration and recursion.

It's always better to go with iteration than recursion in terms of performance, as well as a typical For loop will outperform a foreach loop due to the boxing and unboxing overhead.

Check the traffic, CPU & memory utilization for resource bottleneck.

The last option is to review the entire architecture of the application (a PM's nightmare as that means a lot of time and resource needs to be pumped into the project). If good architectural designs was laid in place before development start, it wouldn't have to come to this point :)

Friday, April 2, 2010

Consuming .NET webservice using Java (netbeans 6.8) in 2 mins

I'm not a very Java person, but i was tasked to assist a team of Java developers using Solaris server. (A .Net developer's nightmare) I'm a GUI person and didn't like the command line concept, well it's powerful and have very little overhead but i need time to learn before jumping into it.

I told the team that i'm a .NET person, not a java guy. They told me leave the console/terminal/ftp to them, just help them to consume a .NET web service. Good.

I asked them from the WSDL file and went to research how java can consume a web service.

Luckily, there was a lot of resource out there documenting how to consume web service in netbeans.

First, create a New Project in NetBeans, give it a meaningful name.
Second, add a file and select "Web service" tab.
third, browse the wsdl file and click "Finish".

Now NetBeans will auto generate all the dependent files.

Expand the tree under your webservices and you will be able to see the web methods with red dots.

Drag and drop them into your methods and all the objects will be automatically instantiated and invoked with default values.

Using your java DAO(Data Access Objects) or equivalent and assign them the correct values and hit then run button.

There you go, java consumption of .NET web service in under 2 mins.