November 27, 2001 - Web Service Basic Authentication | WebReference

November 27, 2001 - Web Service Basic Authentication

Yehuda Shiran November 27, 2001
Web Service Basic Authentication
Tips: November 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Some Web services require basic authentication. Usually, they require a user name and a password. You need to send these two items to the Web service via the call object. You just assign the appropriate properties of the call object:

function callSynch() {
  var co = webServiceCallerBody.createCallOptions();
  co.funcName = "echoString";
  co.async = false;
  co.userName = "guest";
  co.password = "guest";
  var oResult = webServiceCallerBody.echo.callService(co, "Synchronous Call");
  handleResult(oResult);
} 
The ID webServiceCallerBody is the ID of the element to which you attach the WebService behavior, like here:

<BODY ID="webServiceCallerBody" onload="loadService()" 
  STYLE="behavior:url(webservice.htc)>
And the function callSynch() is called by clicking a button:

<BUTTON ID="b2" onclick="callSynch()" disabled>Call Synchronously</BUTTON>
Some Web services require the exact port number that you are trying to connect to. You specify it with the port property of the call object, like here:

function callSynch() {
  var co = webServiceCallerBody.createCallOptions();
  co.funcName = "echoString";
  co.async = false;
  co.userName = "guest";
  co.password = "guest";
  co.port = "Port1";
  var oResult = webServiceCallerBody.echo.callService(co, "Synchronous Call");
  handleResult(oResult);
}