ASP.NET Web Services Part 2

You may have noticed that this post is about two months late. Time flies, doesn’t it? The previous post on an introduction to web services and how they work with ASP.NET provided you with a cursory glance. This post will provide you will how to implement a very basic web service both on the server side for consumption and the client side for use in an application.

Prerequisites

  • Visual Studio 2005 or 2008
  • Basic knowledge of C#
  • Basic knowledge of ASP.NET Web Services

Step 1 – Create the ASP.NET Web Service

  • Visual Studio –> File –> New –> Project… –> Visual C# –> Web –> ASP.NET Web Service Application

Once the web service application project is created, notice that a templated web service was also created (Service1.asmx). The only section of this template to be worried about at the moment is the HelloWorld method marked with the [WebMethod] attribute. Marking methods as a [WebMethod] identifies that they will be used by an external caller through XML SOAP communication and are required to be exposed by the web service WSDL described in the previous post.

  • Make sure the HelloWorld method looks exactly like below.

  • That is literally all it takes to expose a web service method to the world! Press F5 to begin debugging this application in a local web server and continue to Step 2.
Continue reading

ASP.NET Web Services

NOTE: Microsoft no longer suggests using this method of web services, but it is useful knowledge if you are supporting legacy systems or are still required to implement these features for business purposes. This method of web service is still useful for internal operations that do not require high security.

Below is an overview image of common web service architectures. It’s easiest to think of web services at “web methods” contained within a “web library” that contains methods to be executed on a server. The strength of this approach is that all communication is done in a standard XML format, regardless of the platforms communicating. This allows for brand new systems to communicate with extremely legacy systems, assuming that each system can properly implement a valid SOAP request and response according to the WSDL contract.

Client: Any application that requires consumption of whatever methods the web service is exposing.
Web Server: A process that hosts the web services for consumption.
Broker: Provides the definition of the web services being exposed.
SOAP: XML formatted request and results containing data according to the WSDL (see below.)
WSDL: Definition language describing which method to execute, what parameters the method requires, what data types the parameters are, what results will be returned from the web service, and what data type to expect back from the web service.

A common SOAP request with a body but no header. Note that the method being executed is defined in the <m:GetStockPrice> tag and the parameters passed are described in the <m:StockName> tag.… Continue reading

Object-Oriented Connection Class in PHP

I started out in professional web development by using ASP.NET, so I was spoiled by the fact that Microsoft offers a SqlConnection class to use for various database related connectivity features. When I started with PHP, I decided to do some research and write a similar (albeit, much simpler) Connection class. Keep in mind that this class example only supports MySQL.

I started by defining some members of this class and came up with six useful members.

  • Database connection object returned from mysql_connect
  • Boolean to determine if the connection is currently open or closed
  • Database server host name
  • Database catalog name
  • Database user
  • Database password

In order to use this class, we need to add a constructor. I began by creating a default constructor that simply initializes values of the member properties. Take notice that not all of the properties are initialized by the default constructor. $dbConnection is not initialized until the Open() method is called and $isConnectionAlive is already false by default.

Now that the class can be instantiated, we need to add methods to allow operations.… Continue reading

Simple Class Declaration and Initialization with PHP5

If you’re used to classes with C#, C++, and Java, then you’re used to classes in PHP as well. If you’re brand new to classes, I suggest you read up on the definition and uses of them before trying to implement them via this tiny tutorial.

To begin, let’s create a simple class that will store information about a logged in user from a session. This class should hold the user’s username, first name, and last name to identify who it is on subsequent pages and requests. Begin by naming this class as “UserPassport” and adding the three previously described properties. They should not have default values because the class does not make sense without properties assigned during construction.

Expanding on this class, we need to add a constructor and a method to use these properties in a semi-meaningful manner.

There’s nothing crazy going on in the constructor.… Continue reading

Solving a Simple ODE with Simulink

If you have just started learning Simulink, one of the easiest tasks is solving a simple ordinary differential equation. In fact, most of the beginning guides you will find through web searches will probably be similar to the example I am going to provide. Let’s start by assuming you have the following common spring-damper system. For reference, m is mass, c is the damper coefficient, k is the spring coefficient, x is the position, x-prime is the velocity, x-double-prime is the acceleration, and f(t) is a step-input function with a magnitude of 3.

p1formula

We begin first by solving for the second derivative of x. In this case, it ends up solving to:

p1formula_s

Now, it is time to place this into Simulink using the following blocks:

  • 2 integrator blocks
  • 3 gain blocks
  • 1 sum block
  • 1 step input block
  • 1 scope output block

Step 1) Connect two integrator blocks together to simulate a double integration as seen below:
step1

Step 2) Add the appropriate gain blocks to simulate c*x’ and kx.
step2

Step 3) Add the sum block to simulate f(t) – cx’ – kx.
step3

Step 4) Add the gain block after the summation to simulate the multiplication of (1 / m) and the step input function as the third input to the sum block added in Step 3. Make sure the step input function has the properties of Step Time = 0, Initial Value = 0, Final Value = 3.
step4

Step 5) Add the scope block for output after the second integration to view the plotted contents of the numerical solution.… Continue reading

Generating Pseudo Random Numbers in MATLAB

I wrote the code found in this post in the Student Version of MATLAB R2009a (7.8.0.347) on Windows Vista SP2.

This function will return a vector of size i containing randomly generated numbers uniformly distributed between 0 and 1.… Continue reading

Windows Vista – Moving C:Users to Another Location

Moving your personal documents to a location other than the system partition is a good idea for several reasons. Namely, if your system crashes, you can format and reinstall Windows without affecting your personal files or requiring you to move them to another location. Of course, this does not work if the entire drive crashes and takes your personal files with it!

Follow these steps (D: is the name of my location, change it to match yours):

  1. Backup your C:Users folder to an external location
  2. Boot from Windows Vista install DVD
  3. Click “Repair” from main install screen
  4. Click Command Prompt
      • robocopy C:Users D:Users /mir /xj
      • rmdir /S /Q C:Users
      • rmdir “C:Documents and Settings”
      • mklink /J C:Users D:Users
      • mklink /J “C:Documents and Settings” D:Users
      1. Reboot

      You’ll notice that C:Users now has an arrow on its icon designating that it is a link to another location. Remember to set proper permissions and remove read-only status from the new D:Users so all applications work properly!… Continue reading

      Creating a Professional ToolStrip in Windows Forms Part 2

      In my previous post, I explained how to create the basic UI elements of a simple Windows Forms application with a nice looking vertical ToolStrip menu to host buttons and labels without ever leaving the Designer. In this post, I’ll explain how to wire up some events, load in some UserControl objects, and add a custom rendering method to style our MouseClick events on the ToolStrip buttons. We’ll begin by opening the project from our previous post. (seen here)

      Prerequisites

      • Microsoft Visual Studio 2008 (or 2005, but I wrote this using 2008)
      • .NET Framework 3.5 (or 2.0, but I wrote this using 3.5)
      • Basic x,y coordinate knowledge to draw and position rectangles
      • Intermediate knowledge of C# and Windows Forms
        • Inheritance and overrides
        • Event handling

      Step 1 – Create a Custom Rendering Class

      • Right click on the Project in the Solution Explorer, Add –> New Item… –> Class (.cs).
      • Name this class customRenderer.cs and click OK.

      This class is going to inherit from ToolStripProfessionalRenderer so that we can override some of the rendering methods and make them do whatever we want. In this case, however, we will only be overriding the OnRenderButtonBackground method.

      By overriding this method, we can change the behavior of how backgrounds are rendered. Some conditions will need to be applied in order to enforce that custom rendering only occurs on ToolStripButton objects and only when the objects are in a Checked state.… Continue reading

      Creating a Professional ToolStrip in Windows Forms

      Ever wanted to create a professional looking menu in your Windows Forms applications complete with big buttons, nice mouse over effects, and images? Well, look no further. In this post, I’ll show you how to implement a graphical ToolStrip menu to navigate through a Single Document Interface (SDI). You’ll notice that the finished interface is rather similar to Spybot – Search and Destroy. Keep in mind that the following example is rather simple and leaves a lot of room for expansion.

      Prerequisites

      • Microsoft Visual Studio 2008 (or 2005, but I wrote this using 2008)
      • .NET Framework 3.5 (or 2.0, but I wrote this using 3.5)
      • Beginner’s Knowledge Windows Forms

      Step 1 – Create the Form Shell to Host the Menu

      • Create a new Windows Forms Application Project.
      • Select Form1 and adjust it’s size in the Properties Window to 964,600 (the exact size isn’t important, but you want to leave room for other controls once the menu is operational).

      Step 2 – Add the Menus

      • From the Toolbox:
        • Drag in a MenuStrip and snap it to the top of Form1 by either dragging it until the blue line snaps to the top of the form, or drop it in Form1 and set the MenuStrip object’s Dock property to Top.
        • Drag in a TableLayoutPanel to the center of the form.
          • From the submenu that pops up when you drop in the TableLayoutPanel, click “Remove Last Row.”
          • Set this new Container’s Dock property to Fill.
          • From the Toolbox, drag in a ToolStrip and drop it into the left column of the new TableLayoutPanel.
      Continue reading