Calling iSeries DB2 web services from .Net

Problem

Instead of giving you direct access to make DB2 calls to your corporate iSeries, your IT department is exposing iSeries database capabilities via web services provided by IBM’s WebSphere.  Sounds great, but as you’ve experienced, it’s a major pain because they’re not implemented the way you expect.

Solution

  1. Get the URL from your iSeries team for their web service.
  2. In your .Net project, right click “References” or “Service References” and choose “Add Service Reference”.
  3. In the “Add Service Reference” dialog, enter the URL they provided to you into the “Address:” field.  Be sure you add “?wsdl” to the end of it if it’s not already there then click “Go”.
  4. You might be prompted for credentials.  Be sure to get those credentials from your iSeries team.  You will likely be prompted to enter them 3 or more times.  Yes, it’s a nuisance, but just do it.

Now you’ve got the web services added, but you’ve got some config file editing to do.

In your app.config or web.config file, find your custom binding for this service.  If you had to enter credentials, you’ll need to change the httpTransport to what you see below, but the realm will be different.  Get that from your iSeries team.

<customBinding>
  <binding name="Some_Crappy_NameServicesPortBinding">
    <textMessageEncoding messageVersion="Soap12" />
    <httpTransport authenticationScheme="Basic" realm="Secure_SOMETHING" />
  </binding>
</customBinding>

If your iSeries requires credentials, you’ll need to set them on your web proxy like this before you call a method:

ClientCredentials.UserName.UserName = username;
ClientCredentials.UserName.Password = password;

Now, to call a method on the web service is quite different.  You’ll have 4 classes provided in your proxy:

  1. Input
  2. Request
  3. Response
  4. Result

Each one has a name prefixed with “fweb” and some number.  For example, “fweb12Input”.  Each web service your iSeries team adds will have a new number.  Yes, this is entirely backasswords and highly inconvenient, but that’s the way IBM has done it.

You’ll want to instantiate a request object.  It has a field called “arg0” in it.  You’ll want to assign that to a newly instantiated Input object.  The Input object has fields in it representing what would normally be parameters to a web method.  Here’s an example:

var request = new fwebr024Request
{
    arg0 = new fwebr024Input
    {
        IN_FIRSTNAME = "John",
        IN_LASTNAME = "Smith",
        IN_SESSIONID = "Whatever",
        IN_USERID = "DOEJANE"
    }
};

Then you’ll call the web service like this:

var result = this.MyServiceProxy.fwebr024(request);

The result object will have the output of the web service.  It has a strangely named field called “@return”, which is an object with 3 fields representing any error that might have occured:

  1. OUT_ERRCODE
  2. OUT_ERRSTATE
  3. OUT_ERRTEXT

That’s it.  It’s pretty harry, but that’s how you do it.

See these images?

image

You’ll find actual working versions of them at the top and bottom of this article. Please click the appropriate buttons in it to let your friends know about this article.

Check back later for updates too!