Tuesday, June 30, 2009

Call Web Service Function via Javascript using AJAX

The implementation of calling a web service function via javascript has become so tremendously easy with Microsoft’s AJAX components. That’s why I’m writing this blog for me to be reminded that I no longer have to worry of writing a special handler to manage the different implementations if the client is using IE or Firefox or Safari or Chrome. Everything is pretty much taken care of by the AJAX components. The beauty part of it also is I can use the dot notation to access the values in the returned objects.

First step is to create a web project in VS 2008 - Target framework: .NET 3.5

Add New Web Service Item

Configure the web service to allow a javascript call
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {

}

Inside the web service item, I created a custom struct as my data holder
public struct Note
{
public DateTime DateTimeStamp;
public string Comments;
}

I created a couple of functions (getDateStampedNote and getNotes)
[WebMethod]
[XmlInclude(typeof(Note))]
public Note getDateStampedNote(string comments)
{
if (comments == string.Empty)
throw new Exception("Exception: comments must not be empty.");

Note note;
note.DateTimeStamp = DateTime.Now;
note.Comments = comments;
return note;
}

[WebMethod]
[XmlInclude(typeof(Note))]
public ArrayList getNotes()
{
ArrayList ar = new ArrayList();
ar.Add(new Note
{
DateTimeStamp = DateTime.Now,
Comments = "First Note"
});

ar.Add(new Note
{
DateTimeStamp = DateTime.Now,
Comments = "Second Note"
});

ar.Add(new Note
{
DateTimeStamp = DateTime.Now,
Comments = "Third Note"
});

return ar;
}

Note: import XML serialization library in the web service.
using System.Xml.Serialization;

In default.aspx, I added a script manager and inside that I referenced the web service that I just created.




Same aspx file, I added a bunch of javascript functions (but reusable):
function dateStampMyComments()
{
//get comments value
var comments = document.getElementById("comments").value;
WebService.getDateStampedNote(comments,processResultSucess,processResultFailed,Object);
}

function getNotes()
{
WebService.getNotes(processResultGetNotes,processResultFailed,Object);
}

function processResultGetNotes(result)
{
for(index in result){
note = result[index];

document.getElementById("notes").innerHTML = document.getElementById("notes").innerHTML + "
" + note.Comments + " - " + note.DateTimeStamp;
}
}

function processResultSucess(result){
alert(result.DateTimeStamp + " - " + result.Comments );
}

function processResultFailed()
{
alert("Webservice Failed \n" + result._message);
}





Wednesday, February 4, 2009

Automatically mapping a user to a login in SQL Server

Automatically mapping a user to a login, creating a new login if it is required

The following example shows how to use Auto_Fix to map an existing user to a login of the same name, or to create the SQL Server login Mary that has the password B3r12-3x$098f6 if the login
Mary does not exist.

EXEC sp_change_users_login 'Auto_Fix', 'Mary', NULL;
GO


for more info, go to msdn website at:

http://msdn.microsoft.com/en-us/library/ms174378.aspx

Tuesday, September 30, 2008

Scripting the Creation and Deletion of a Replication in SQL Server

How to: Create a Push Subscription (Replication Transact-SQL Programming)
It seems like this is only available on SQL Server 2005 and possibly on 2008 as well. Unless, there is a plug-in for SQL Server 2000, which I doubt it.

To know more about the details on how-to create a push, click on the links below:
http://msdn.microsoft.com/en-us/library/ms146912(SQL.90).aspx
OR
http://msdn.microsoft.com/en-us/library/ms146912.aspx


How to: Delete a Push Subscription (Replication Transact-SQL Programming)
This is OK if you can live to have some residual information related to the subscription. But have no fear, there is a follow up SQL command that will do a clean up in the subscriber database, which will get rid of the unnecessary metadata. Even though the commands work on SQL Server 2000, I still prefer the manual process of deteting the subscription using Enterprise Manager because of the cleanliness that it can provide me.

For more info go to:
http://msdn.microsoft.com/en-us/library/ms146944(SQL.90).aspx
OR
http://msdn.microsoft.com/en-us/library/ms146944.aspx

adios!

Wednesday, September 24, 2008

Missing Assembly in GAC

I was getting this error when I try to run my App based on 3.5 framework – I found out that ADODB.dll and System.Core.dll were not registered in the Global Assembly Cache (GAC). For some reason, these two important DLLs did not register during the installation of .NET 3.5 framework.

Error Message:
Could not load file or assembly 'ADODB, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.


So, what I did is I got a copy of the missing ADODB.DLL and pasted it in the new server. I installed the ADODB assembly and that fixed my problem.


For the System.Core, I just simply registered it using the DLL file located at C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5 folder.

There are four ways to install an assembly into the global assembly cache:

1. Using the Global Assembly Cache tool (Gacutil.exe).

2. Using Microsoft Windows Installer 2.0.

3. Using a Windows shell extension provided by the Windows Software Development Kit (SDK) called the Assembly Cache Viewer (Shfusion.dll).

4. Using the .NET Framework Configuration Tool (Mscorcfg.msc).

My favorite procedure is using .NET Framework Configuration. It’s really easy.

For more information on how to install assembly into GAC, go to:

http://msdn.microsoft.com/en-us/library/dkkx7f79.aspx


Monday, August 11, 2008

Flag Project

My 3-year-old son has inspired me to build this application. The idea is really simple. The program will help me teach my son about different flags, countries and capitals in a very fun way. In addition to that, my son will be able to point out countries on the map and will encourage him to love geography which I have struggled :)

check it out at:

http://www.witoe.com



Tuesday, July 29, 2008

Why Mac?

My lifestyle when it comes to work is spontaneous - whether it is a duty call such as troubleshooting and fixing website issues remotely during the weekend or learning and researching new technology on the couch of my living room. Having a laptop has always been a useful tool for me. It liberates me from working in a cubicle that may not have all the inspirations I have on designing and developing software applications.

Working as a software developer, I feel that I am responsible for my growth and advancement in the technology arena. However, executing that responsibility requires necessary tools to further practice the importance of software development and quality assurance. That being said, Macbook Pro of Apple will provide me more exposure to the cutting-edge operating systems available in the market, allow me to test and evaluate software applications in a diverse environment and give me the best way to explore the world of iPhone development.

First and foremost, using Mac OSX and Microsoft Windows Vista on a daily basis at work will augment my software development skills. It is like having a skill to speak two different languages. It is like knowing how to write C# and Java programs. It is like being able to script a scheduled job for DOS or Unix-based environment. Seeing and discovering both OS’s pros and cons is definitely a plus. This will surely give me ideas on how to develop a much more intuitive Graphical User Interface designs for the web and desktop applications. Another important thing is I will be able to understand and pick up some schemes on how to apply a better User Interface Friction (UIF is the resistance imposed upon a user-guided process through the operating system and the way the user interface reacts) to my applications to potentially increase the users’ productivity. I personally think that most of developers’ works are influenced by the operating system that they use on a daily basis on their job.

It is clear now that Mac OSX has become a lot more popular in schools and companies. Let’s take the OS market share report of a Technology Analyst at Stanford University as an example. Only 7 percent of the users using Vista and 30 percent are Mac OS users. Another interesting note on his blog is that 1/3 of the computers on Stanford campus have been purchased since the release of Vista. It’s a good thing for the institution to be proactive when it comes to technology. The academia part of CZS may be supporting different operating systems and types of hardware system in the future. Though currently the institution is Microsoft centric, but being able to test software in different environments will help me determine and identify what system is best for interoperability.

Lastly, iPhone development has become a lot more common and may be the next mobile device that would replace the PalmOS devices. The fact that Apple is opening their iPhone development tools to the public, which is really a big step. It encourages developers to cultivate the technology. Enterprise integration, such as Microsoft Exchange, for iPhone has already started and I see a trend of a successful continuity in the future. Mac OSX is the only legal way that I know to run iPhone’s Software Development Kit. Being able to ride on the next big Kahuna in mobile computing is a substantially awesome thing to have – working with a popular, intuitive and non-stylus personal device application called iPhone.

Macbook Pro will be beneficial to my growth and advancement within the society. This will open a new window of opportunity to explore new technology that is not only available, but also the best for the institution. Once I go Mac, I can never go back ;)




Sources:
http://www.pfeifferreport.com/trends/trend_vistauif.html
http://www.jacobpierce.com/blog/2008/06/07/stanford-university-os-study/

Monday, July 14, 2008

Sample code on how to call a javascript function in OpenLaszlo

function callMe(objCaller,message){
objCaller.animate("width",100,1000,false);
LzBrowser.loadJS('alert(' + '"' + message + '"' + ')');
}