Tuesday, 23 April 2013

How to use the Oracle Imaging API Search Service with .Net

Introduction

I recently had to work out how to implement the Oracle Imaging API Search Service in Microsoft .Net, so that I could use a saved search. This proved to be a challenge on a number of fronts, so I have decided to record the process here.

Importing the Service

Importing the service was the easy part. As it is a standard web service I just had to import the WSDL. Importing the Search Service requires the following URL:

http://[server address]/imaging/ws/SearchService?WSDL

In Visual Studio you need to add a service reference, which will give you the following dialog.

Add Service Reference
Put the URL into the address and press "Go". Once the WSDL has been imported you can choose a namespace and press OK. I used "Oracle.Imaging" as the namespace.

Security and Configuration

The Oracle API requires a username and password to be supplied. Working out how to do this, however, is no easy task. Like many things though, when you know how it turns out to be easy.

The App.config file contains configuration for the web service. the element contains an child element with a number of attributes. You need to add extra elements under then endpoint so it looks something like the following:

Security Configuration

Depending on how much data you expect to receive back, you may need to increase the buffer size as well. To do this, you will need to add some extra attributes to  the binding. Where you have you will need to add the attributes maxBufferSize and maxReceivedMessageSize. The values for the attributes should be identical and will be a number of bytes.

Using the Service

To actually use the service you need to instantiate a SearchServiceClient instance. You can then use the executeSavedSearch method to actually invoke a saved search on the server. The arguments to this method are a NameId instance and an array of SearchParameter.

Creating the NameId is straightforward, but there are a few gotchas that one needs to be aware of when creating the search parameters.

The general process involves creating a SearchParameter, a SearchValue, and a TypedValue. The TypedValue will be assigned to the typedValue property of the SearchValue and the SearchValue will be assigned to the parameterValue property of the SearchParameter.

for the saved search, all value types must be set to TEXT and it is very important that the typeSpecified property of the TypedValue is set to true. If it is not then an important attribute will not be included in the SOAP request and incorrect results will be returned.

The following is an example of creating a search argument for a "SUPPLIERID" parameter.

             searchArguments[0] = new SearchParameter();
             value = new TypedValue();
             value.type = FieldType.TEXT;
             value.Value = supplierId;
             value.typeSpecified = true;
             searchValue = new SearchValue();
             searchValue.searchValueType = SearchValueType.TEXT;
             searchValue.typedValue = value;
             searchValue.searchValueTypeSpecified = true;

             searchArguments[0].parameterName = "SUPPLIERID";
             searchArguments[0].parameterValue = searchValue;
             searchArguments[0].operatorValue = @operator.EQUAL;
             searchArguments[0].operatorValueSpecified = true;

And that should be all you need to know to successfully consume the Oracle Imaging API from your .Net application.