The SoapConnection class is used to create a proxy object for a specific Web service and set options for the connection.
SoapConnection has the following methods:
The GenerateProxy method is currently not implemented.
Creates a proxy instance with a default URL for a SOAP server, which comes from a user-supplied WSDL file. The client application must create a proxy instance before it can access a Web service.
conn.CreateInstance (ref powerobject proxy_obj, string proxy_name, {string portname}) throws SoapException
Argument |
Description |
---|---|
conn |
The name of the SoapConnection object that establishes the connection |
proxy_obj |
The referenced name of your proxy object |
proxy_name |
The name of the proxy, based on the port name from a URL in the WSDL file stored in the proxy |
portname |
(Optional) The port name from a URL not stored in the proxy |
Long. Valid values are:
Value |
Description |
---|---|
0 |
Successful |
100 |
Invalid proxy name |
101 |
Failed to create proxy |
In this example, the client application creates a proxy instance to access the Web services at http://my.server/soap/myport. The proxy name "syb_myport" is generated by the Web Service Proxy wizard when you select "syb_" as a prefix for a service port (endpoint) called "myport".
syb_myport myproxy long ret ret = Conn.CreateInstance(myproxy, "syb_myport", "http://my.server/soap/myport")
The following script creates a connection to a Web service on a SOAP server. It sets the connection properties using an endpoint defined in the CreateInstance method. (If the endpoint is not defined in the CreateInstance method, a default URL stored in the proxy is used). The script uses the SetOptions method to specify a log file. It displays a return value in an application message box:
SoapConnection conn // Define SoapConnection syb_currencyexchangeport proxy_obj // Declare proxy long rVal, lLog real amount //Define endpoint. You can omit it, if you want to use //the default endpoint inside proxystring str_endpoint str_endpoint = "http://services.xmethods.net:80/soap" conn = create SoapConnection //Instantiated connection lLog = conn.SetOptions("SoapLog=~"C:\mySoapLog.log~"") // Set trace file to record soap interchange data, // if string is "", disables the feature rVal = Conn.CreateInstance(proxy_obj, & "syb_currencyexchangeport", str_endpoint) // Create proxy object try amount = proxy_obj.getrate("us","japan") // Invoke service messagebox("Current Exchange Rate", "One US Dollar"& + " is equal to " + string(amount) + " Japanese Yen") catch ( SoapException e ) messagebox ("Error", "Cannot invoke Web service") // error handling end try destroy conn
After you instantiate a proxy, you are ready to call the SOAP methods you want from the associated Web service port.
Sets connection options for SoapConnection class. The string values for the option names are not case sensitive.
conn.SetOptions (string Options)
Argument |
Description |
---|---|
conn |
The name of the SoapConnection object that establishes the connection. |
Options |
Options you want to set for your connection. These can be:
|
Long. Valid values are 0
for
success, and 50
for failure.
If multiple options are specified and the return value is 50
,
options specified before the failure are still valid.
In this example, the application enables the logging function and attempts to connect to an endpoint for which no user ID, password, or timeout has been set.
lOpt=Conn.SetOptions("SoapLog=~"airportweather.log~"")
If you do not want to use escape characters before a second pair of quotation marks, you can use single quotation marks instead, or you can start an exterior string with single quotation marks and use double quotation marks around an interior string:
lOpt=Conn.SetOptions('SoapLog="airportweather.log"')
User ID and password values can be set in an endpoint used by the SoapConnection class or by including these values as arguments to the SetOptions method.
Priority is given to values set in an endpoint (port) that is passed as an argument to the CreateInstance method of the SoapConnection class. However, a default endpoint is used when an endpoint is not set in the CreateInstance method. In this case, priority is given to user ID and password values defined in the SetOptions method.
If the endpoint used by the SoapConnection class does not have user ID and password values, and you do not set a user ID or password with the SetOptions method, the SoapConnection class connects to a SOAP server without giving a user ID or password.
If a user ID is defined in either the endpoint or the SetOptions method but is not a password, the password value is taken to be an empty string.
When you set a timeout other than the default, an exception is thrown after the Web service connection times out. Even if you do not set a timeout value from the client, the Web server can still cause the request to time out on the server side.
If you include ConnectionCache as an argument in a SetOptions call, you must not use quotation marks to enclose the value that you set for this option.
Sets the proxy address, user name, and password for the proxy server.
conn.SetProxyServerOptions (string optionstring)
Argument |
Description |
---|---|
conn |
The name of the SoapConnection object that establishes the connection. |
optionstring |
A string containing comma-separated name/value pairs. The format is: "address='proxy_endpoint '{, userID='name ', password='password '} " The address is required and can have a format such as: http://hostname:port/path Specify values for userID and password if the proxy server requires them. |
Long. Valid values are 0
for
success, and 50
for failure.
This example specifies a user name and password, as well as the proxy endpoint:
long ll_return
string ls_string
ls_string = "address='http://Srvr:8080/endpnt'," ls_string += "userID='MyName', password='mypass'" ll_return = Conn.SetProxyServerOptions (ls_string)
Use this function if the proxy server requires authentication. The user ID and password you can supply with the SetOptions function apply to the URL of the service, not the proxy server.