Using Nematrian Web Functions in more
sophisticated programming environments such as Visual Studio
[this page | pdf | references | back links]
As
explained in Web
Services Introductory Pages, the Nematrian website provides a wide range of
web services that users can access directly via the Internet. To do this, the
user needs to include calls to the relevant web services within some suitable
software container, e.g. in programs written in VBA code within Excel (or
another Microsoft Office application), see here, directly in
a web page in HTML and Javascript or in software written using Visual Basic or
C++ code, see below.
In what follows we assume that users are trying to access Nematrian web
functions using via Visual Basic within Visual Studio although many other
Software Development Kits (SDK) operate in a relatively similar fashion.
We suggest that you first try accessing Nematrian web services by inserting
into your browser the following URL: http://www.nematrian.com/WebServices.asmx
If this comes up with a long list of functions then you should be able to
access Nematrian's web service functions using this URL or equivalent URL's for
other Nematrian public servers. Almost all of the web services accessible via
this .asmx page require you to have a live Nematrian site Session ID, with the
exception of 'Complex Sum'.
Almost all Nematrian web service functions return back answers using a bespoke
structure that includes an error flag, an indication of the amount of
credit deducted from your Session
Id when you ran the function and the result of running the function (if the
error flag was not triggered). This is to make the functions as versatile as
possible. The elements in each structure are called .ErrFlag, .Debit and
.Answer respectively. .ErrFlag is a String variable and .Debit is a Double
variable. The structure taken by .Answer varies according to the purpose of the
function and can be found from the relevant function description
page.
To access the software within your code you first need to add a reference
to the relevant software (e.g. by using the Add a web reference command
in the "Website" drop-down menu). The dialogue box opened via this
Visual Studio menu command allows you to browse for the URL for the web service
you are attempting to access. To avoid excessive usage of a single URL, the
Nematrian web site may distribute its delivery of web services across several
parallel web sites (i.e. several URLs). Where practical, it will endeavour to
assign you the same URL whenever you log in (to avoid you needing to recompile
your code to refer to a new reference URL). The dialogue box allows you to name
the Nematrian web service anything you like; it is assumed below that you have
called it mnWebService.
Software along the lines of the following will then, for example, call the
Nematrian Sudoku Solver (it is assumed here that you are using Visual Basic as
the programming language within Visual Studio):
Option Explicit On
Imports System.Web.Services.Protocols
Private Function SudokuSolve( _
ByVal SessionID As
String, _
ByVal SudokuType As
String, _
ByVal BaseStartingData() As Byte, _
ByVal IterationLimit As Integer) As
mnWebService.mnSudokuSolution
Dim ws As New
mnWebService.WebServices
SudokuSolve = ws.SudokuSolve(SessionID, SudokuType, BaseStartingData,
IterationLimit)
End Function
The input parameters for this function (and the corresponding web service) are:
Name
|
Type
|
Description
of Variable
|
SessionID
|
String
|
User's SessionID as obtained by logging into the Nematrian
website
|
SudokuType
|
String
|
Type of Sudoku puzzle being solved, "Standard",
"Samurai", "Killer" or "General"
|
BaseStartingData()
|
Byte
|
Unidimensional byte array that contains the base starting
data
|
IterationLimit
|
Integer
|
a large number (e.g. 100000) limiting no of iterations
Solver will execute
|
The output of this function has the following structure
Structure mnSudokuSolution
Dim ErrFlag As
String
Dim Xcoord() As
Byte
Dim Ycoord() As
Byte
Dim SolutionValue() As
Byte
Dim TimeTaken As
Double
Dim NoTimesAccessed As
Integer
End Structure
So, for example, we can tell whether the Sudoku puzzle has a (unique) solution
by using code such as:
Dim SudokuSoln As
mnWebService.mnSudokuSolution
Dim ErrFlag As String
SudokuSoln = SudokuSolve(SessionID, SudokuType, BaseStartingData,
IterationLimit)
If SudokuSoln.ErrFlag<>"" Then
...
End If
Disclaimer
Users should not insert software generated by the website
into their own programs or spreadsheets unless they understand what it does and
are sure that it will not damage or corrupt any of their existing work.
The Nematrian website takes no responsibility for losses
arising from use of code sourced from this page or from its web service example
code generator facility.
Please bear in mind that it is possible that hackers may
tamper with the Nematrian website and introduce malicious code in the hope that
you will run this code assuming that it will work as you expect. If you have
any doubts about whether the code you see on this page may be malicious then
please refer to an expert.
Use of the Nematrian website, including its web services, is
subject to the terms of the Nematrian License
Agreement. By making use of the site, including its web services
functionality, you agree to be bound by this Agreement.
NAVIGATION LINKS
Contents | Prev