Developer Resources’s Weblog

June 9, 2008

Python web service using SOAPPy

Filed under: Examples, Python, Web Services — Tags: , , , — developerresources @ 5:10 am

Here is an example of how to call a WebService from Python. For more information on Python and Web Services I recommend the following book: Python Cookbook.

This requires the fpconst and SOAPPy package. You can download them from http://research.warnes.net/projects/RStatServer/fpconst/ and http://prdownloads.sourceforge.net/pywebsvcs/SOAPpy-0.11.6.tar.gz?download. Unzip the packages then run python setup.py install on each package.

The following code will then connect to the web service and execute the remote method.

import sys

#Import the ZSI client
from SOAPpy import WSDL

url = 'http://webservices.daehosting.com/services/isbnservice.wso?WSDL'
server = WSDL.Proxy(url);
print server.IsValidISBN13(sISBN ='0000000000000')

Note there is another web service package called ZSI, I found SOAPPy to be easier to use, but from what I understand both packages are going to merge together.

June 8, 2008

C# Web Services

Filed under: C#.NET, Web Services — Tags: , , — developerresources @ 11:52 am

This Post illustrates how to write a simple C# Soap Client.

For more information about C# I recommend the following book: Programming .NET Web Services.

C# is not an interpreted language like Perl or Python, so before you can consume a web service you must first generate a stub class. In Visual Studio click Tools->Visual Studio Command Window

In the command window type wsdl this will generate a c# stub file your current directory. Copy this file into your c# project.

For an example lets use the following web service: http://www.webservicex.net/stockquote.asmx?wsdl.

This will create a stub file called StockQuote.cs.

To call this service you just need the following code



using System;
using System.Collections.Generic;
using System.Text;
namespace TestWebService
{
  class Program
  {
    static void Main(string[] args)
    {
      StockQuote stockQuote = new StockQuote();
      Console.WriteLine(stockQuote.GetQuote("nvda").);
    }
  }
}

Thats it! Make sure to include the System.web.Services references by right click on your project name and selected Add References.

Perl – SOAP Client (using SOAP::Lite)

Filed under: Perl, Web Services — Tags: , , — developerresources @ 11:41 am

This Post shows how to use Perl as a SOAP Client to an existing web service.

For more information on Perl and WebServices I recommend: Programming Web Services with Perl

To access SOAP web services with Perl, I recommend the SOAP::Lite CPAN module. If you don’t have SOAP::Lite already installed you can install it by issuing the following commands and answering any prompts.


perl -MCPAN -e shell
CPAN> install SOAP::Lite

Here is a simple example perl call that calls the stock quote webservice at http://www.webservicex.net/stockquote.asmx?wsdl.


use strict;
use SOAP::Lite +trace => 'debug';
my $soap = SOAP::Lite->new();
my $serializer = $soap->serializer();
my $service = $soap->service('http://www.webservicex.net/stockquote.asmx?wsdl');

print $service->GetQuote(“nvda”);

Note: The recent version of SOAP::Lite appears to have a bug, when the service is a newer one like a .NET or axis the above code doesn’t work. I can’t find any indication that SOAP::Lite developers are going to fix this or not. If anyone has any information let me know.

Ruby – Hello World

Filed under: Hello World, Ruby — Tags: , , , — developerresources @ 10:28 am

This Post is the first in a series of post about the Ruby programming languages.

For more information about Ruby I recommend this book: The Ruby Programming Language.

The best way to start any introduction to a new language is with the classic Hello World Program. At this point I assume you already have the ruby interpreter installed. If not you can download it from www2.ruby-lang.org

Once you have the interpreter create a file with the following contents:

puts "Hello World!"

Save the file as helloworld.rb, then execute ruby helloworld.rb. Your output will be “Hello World!”

Accelerated C++ Chapter 2 – Looping and Counting

Filed under: Uncategorized — developerresources @ 9:43 am

The Page continues the discussion of Accelerated C++: Practical Programming by Example (C++ In-Depth Series)

Loops and conditionals are an integral part of any programming language. Chapter 2 of Accelerated C++ introduces the reader to the while, if, logical operators, and constructs.

Being an experienced developer I thought the amount of detail used to explain the how to configure the while construct was a too much. However, I must assume that the author’s had good reason to include so much detail as previous students of theirs must of been confused, and with loops being such an important concept I suppose the added explanation was worth it.

The author then goes on to describe the different built in types for C++:

Types:

bool
Built-in type representing truth values; may be either true or false

unsigned
Integral type that contains only non-negative values

short
Integral type that must hold at least 16 bits

long
Integral type that must hold at least 32 bits

size_t
Unsigned integral type (from ) that can hold any object's size

string::size_type
Unsigned integral type that can hold the size of any string

June 7, 2008

Accelerated C++ Chapter 1 – Working with Strings

Filed under: Accelerated C++, Book Reviews, c++ — Tags: , , — developerresources @ 8:15 am

The Page continues the discussion of Accelerated C++: Practical Programming by Example (C++ In-Depth Series)

Chapter 1 immediately introduces the reader to an object by modifying the Hello World program from chapter 0 to ask the user for his name then saying Hello [user].


#include
using namespace std;
int main() {
cout << "Enter Name: " <> name;

string name;
cin >> name;

cout << "Hello " << name << endl;
return 0;
}

Once again this simple example introduces a lot of new concept. Were introduced to variables, objects,definitions, interfaces, initialization, and the string object.

The String object is the most important concept from this chapter. By using it the reader is introduced to the constructor, and the idea of an interface for the object. For example the reader can now time name.size() to get the size of the object. This new knowledge is put to use to frame the name with a series of asteriks leading to the close of Chapter 1.

Accelerated C++ Chapter 0 – Getting Started

Filed under: Accelerated C++, Book Reviews, c++ — Tags: , , — developerresources @ 5:20 am

The Page starts the discussion of Accelerated C++: Practical Programming by Example (C++ In-Depth Series)

Accelerated C++ is a new approach to teaching C++. It teaches the reader the most useful aspects of C++ instead of starting with teaching C. The reader is introduced to high level data structures from the start. It also focuses on solvings problems through clear examples instead of just explaining the features and libraries as most textbooks tend to do.

The first chapter of this book is named Chapter 0 in reference to zero index arrays. As with all beginning programming books it begins with the Hello World program.

#include
int main() {
std::cout << "Hello World" << std::endl;
return 0;
}

This simple examples teaches a lot. It teaches proper scoping, comments, functions, return values, white space rules, and include directive. The remaining couple pages of chapter 0 explain those issues. The chapter ends with the user having written and compiled their first program and ready to move on.

Chapter 8 – Writing generic functions

Filed under: Accelerated C++, Book Reviews, c++ — Tags: , , , — developerresources @ 3:12 am

The Page continues the discussion of Accelerated C++: Practical Programming by Example (C++ In-Depth Series).

C++ provides templates as an ability to focus on writing generic algorithms for any number of data types. A common example is the stl vector container. When you instantiate the vector obect you provide the type of object that the vector will contain. (vector<int> for example)

In discussing generic function this chapter also focuses on iterators and the different types: Sequential read-only, Sequential write-only, Sequential read-write, Reversible, and Random access.

Chapter 9 – Defining new types

Filed under: Accelerated C++, Book Reviews, c++ — Tags: , , , — developerresources @ 3:10 am

The Page continues the discussion of Accelerated C++: Practical Programming by Example (C++ In-Depth Series)

There are two types in C++ built-in types and class types. Built-in types are part of the core language (int, double, char, etc) whereas class types are typically built on top of the built-in types (vector, string, user-defined classes, etc).

Chapter 9 of Accelerated C++ revisits example from previous chapters and implements them as Classes. For those of you who don’t know a simple class in c++ can be declared as follows:


class MyClass {
std::string my_field;
public:
std::string getMyField() const { return my_field;}
}

The above code declares a class ( all methods default to private access ) with one member field, and one assesor function.

Member Functions
As you see above our classes not only contain data but also member functions. When should you use a member function? The general rule is when the function changes the state of the object.

Accessor functions
Accessor functions are names given to member functions that serve to expose hidden fields of the object.

Constructors
Constructors hold code that is executed upon object construction. More formally, “Constructors are special member functions that define how objects are initialized.”

A constructor can take no arguments, known as the default constructor or it can take variables that you use for initialization.

user-defined types can be defined as either structs or classes. Structs default to always public access, where as classes start with private access.

Protection labels control access to members, both fields and function, of a class or struct. So you can start with a struct and declare parts private, or you can start with a class and decalare parts public.

Constructor initializer list is a comma separated list of member-name(value) pairs that indicate how to initialize the object.

Chapter 10 – Managing memory and low-level data structures

Filed under: Accelerated C++, Book Reviews, c++ — Tags: , , , — developerresources @ 3:09 am

The Page continues the discussion of Accelerated C++: Practical Programming by Example (C++ In-Depth Series)

List of key concepts from this chapter.

Pointers

A pointer is a value that represents the address of an object. Each object in your system has a unique memory address. For example if you have an object ‘x’ then ‘&x’ is the address of x. And if p is the address of an object then *p is the value of that object.

Pointers to functions

In addition to pointing to objects, built-in and class types, you can also point to functions.

int (*fp)(int) // A pointer to a function that takes an int as a parameter

Now if we define a function with the same signature

int next(int n) { return n+1; }

Then the following will assign the pointer


fp = &next // or fp=next works as well

fp=next works above as well since you can only take an address from a function the ‘&’ is implicit. Similarily you can call it either way:

fp(i);
(*fp)(i)

Arrays

An array is a basic container of same objects. int[3] for example. Arrays are not class types so they have no members.

You can initialize an array when you declare it, which is something you can’t do with stl containers.

const int month_lengths[] = {31,28,31,30,31,30,31,31,30,31,30,31 };

Reading and Writing Files
You can write to standard error by using either cerr, or clog.

Example to copy file from one to another


int main() {
ifstream infile("in");
ifstream infile("out");

string s;
while(getline(infile,s))
outfile << s << endl

return 0;
}

Memory management
There are two distinct types of memory management: automatic and statically allocated.

Automatic memory managemt is associated with local variables. The system allocated memory when its first encountered and frees it with variable falls out of scope.

Statically allocated is associated with use of the ’static’ keyword. For example

int* pointer_to_static() {
stataic int x;
return &x;
}

The third way is to allocate memory yourself from the heap through the keyword new.


int* p = new int(42);

« Newer PostsOlder Posts »

Blog at WordPress.com.