Download Configuring and Using the Demo3D SOAP Interfac

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Configuring and Using the Demo3D SOAP Interface
Introduction
Demo3D has a built-in SOAP server which exposes scripting functions as SOAP methods.
This document assumes that the reader has basic knowledge of SOAP and its related
technologies. You will need to use third party toolkits to create the client software. An
example shows how to create a custom SOAP client using Microsoft's toolkit.
Configuration
The SOAP interface is configured via the Scene properties:
Property Details
Enabled
Indicates whether the SOAP server is listening for requests or not. When enabled, the SOAP
server will be listening for requests on the specified port.
Name
Name of the SOAP service. This is used to name the service in the WSDL.
NamespaceUri
URI for the SOAP service. This is used in the WSDL for the service.
Path
The base path used to construct the service URL.
Port
The TCPIP port on which the server listens
Url (read-only)
The effective URL that the SOAP server expects to receive requests on. This is constructed
from the hostname, and the path and port properties.
The only property you may need to change is the Port number, if you suspect that another
process is using the default value of 9080.
Enabling the Service
Set Enabled = True. When you next run your model, the SOAP server will be started, and
this message will be displayed:
Started Demo3DModelService at SOAP server http://TURING:9080/soap
Writing SOAP-Friendly Script
Any function that is defined in the Document script is included in the SOAP service.
However, care must be taken with parameter types and return values.
Try to restrict parameters to the basic types: string, int, float, boolean. Demo3D is able to
serialize other types, but you may find you need to write custom serialization code in your
SOAP client.
Remember that you can use strings to identify visuals; in your script function you can use
doc.FindVisual() to find the visual with that name.
Example Scripting
Your scripting can provide any kind of service you require. Here are some examples of what
your service might do:
-
Move objects
Change colours and/or dimensions of objects
Create and delete objects
Return properties of specified objects
Here is some example scripting showing how to do a few of these functions. Note how the
parameters are all basic types.
function CreateBox( name : String, colour : String, size : Double )
{
var factory : VisualFactory = app.FindVisualFactory("BoxVisual");
var box : BoxVisual = factory.Create(doc);
box.Name = name;
box.Material.Color = System.Drawing.Color.FromName(colour);
box.Width = size;
box.Height = size;
box.Depth = size;
box.WorldLocationY = size / 2;
box.AddCustomProperty( "HUID", System.String, name, "SAP Stock
Unit ID" );
box.CreateMesh();
}
function VehicleMove( name : String, from : String, to : String )
{
var vehicle : Visual = doc.FindVisual(name);
var p1 : Visual = doc.FindVisual(from);
var p2 : Visual = doc.FindVisual(to);
vehicle.WorldLocation = p1.WorldLocation;
vehicle.MoveTo( p2.WorldLocation, 10, 10 );
}
function MoveTo( name : String, x : Double, z : Double )
{
var visual : Visual = doc.FindVisual(name);
if (visual == null) throw new Exception( "No such visual: " + name
);
var loc = visual.WorldLocation;
loc.X = Convert.ToSingle(x);
loc.Z = Convert.ToSingle(z);
visual.MoveTo( loc, 10, 10 );
}
Using Microsoft Tools To Generate a SOAP Client
Microsoft produce a tool named "wsdl.exe" which can be used to generate source code that
can communicate with a SOAP server that can supply a WSDL specification of its service.
You can view the WSDL for a Demo3D model by appending "?wsdl" to the SOAP url for the
model; you should be able to view this from a browser. For example, type this into your
browser's address field (make sure your model is running first):
http://localhost:9080/soap?wsdl
You can pass this same URl to the wsdl.exe tool to have it generate source code for the
service:
$ wsdl http://localhost:9080/soap?wsdl
Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 2.0.50727.1432]
Copyright (C) Microsoft Corporation. All rights reserved.
Writing file 'c:\Users\davidd\Demo3DModelServiceService.cs'.
(If you receive an error at this point, you may need to add a trailing '/' (slash) to the URI
specified for your SOAP service in the model. This has been addressed in later builds of
Demo3D.)
You can now write a simple program to send commands to your model. Here is an example
that will create boxes in your model, if you have used the scripting example shown above:
using System;
public partial class Demo3DModelServiceService {
public static void Main( string[] args ) {
if (args.Length != 3) {
System.Console.WriteLine( "usage: CreateBox name colour
size");
return;
}
Demo3DModelServiceService model = new
Demo3DModelServiceService();
string name = args[0];
string colour = args[1];
double size = double.Parse(args[2]);
try {
model.CreateBox( name, colour, size );
}
catch (Exception x) {
Console.WriteLine( "Error: " + x.Message );
}
}
}
Save this to a file named "CreateBox.cs", and then produce an executable as follows:
$ csc CreateBox.cs Demo3DModelServiceService.cs
Test your client (make sure the model is running):
$ CreateBox MyBox Red 1
You should see a new red box appear in your model.