private void btnGetInfo_Click(object sender, System.EventArgs e)
{
// The getVehicleInformation method accepts an AssetIdentifier and returns a
// VehicleInfo object. Instantiate them both.
qtref.AssetIdentifier ai = new qtref.AssetIdentifier();
qtref.VehicleInfo vi = new qtref.VehicleInfo();
// Replace these strings with valid company name, user name and password
string sUsername = "theusername" ;
string sCompanyname = "thecompanyname" ;
string sIdentity = sUsername + "@" + sCompanyname;
string sPassword = "thepassword" ;
// Create the SOAP context and token. Put the identity and password into the token
// and add the token to the context.
SoapContext requestContext = svc.RequestSoapContext;
UsernameToken userToken = new UsernameToken(sIdentity, sPassword, PasswordOption.SendPlainText);
requestContext.Security.Tokens.Clear();
requestContext.Security.Tokens.Add(userToken);
try
{
ai.scac = " " ; // No SCACs required at this time.
ai.id = "CSDIMCT" ; // Replace with the ID of a vehicle in your fleet
vi = svc.getVehicleInformation(ai); // Invoke the service
// Format some of the resulting vehicle information into a string and
// display it.
StringBuilder sb = new StringBuilder( "" );
sb.Append( "Identifier: " );
sb.Append(vi.vehicle.id);
sb.Append( " Name: " );
sb.Append( "\nPosition Hardware: " );
sb.Append(vi.positionHardware);
sb.AppendFormat( "\nDistance: {0} Direction: {1} {2}, {3} {4} {5} Type: {6} Name: {7}" ,
vi.proximityTown.distance, vi.proximityTown.direction, vi.proximityTown.city, vi.proximityTown.state,
vi.proximityTown.zip, vi.proximityTown.country, vi.proximityTown.placeType, vi.proximityTown.placeName);
sb.AppendFormat( "\nDistance: {0} Direction: {1} {2}, {3} {4} {5} Type: {6} Name: {7}" ,
vi.proximityCity.distance, vi.proximityCity.direction, vi.proximityCity.city, vi.proximityCity.state,
vi.proximityCity.zip, vi.proximityCity.country, vi.proximityCity.placeType, vi.proximityCity.placeName);
lblVehicleInfo.Text = sb.ToString();
}
catch (Exception ex)
{
string sErrorMessage = DateTime.Now.ToString()
+ " Exception during the getVehicleInformation call with error:\r\n"
+ ex.Message + "\r\n"
+ ex.StackTrace;
lblVehicleInfo.Text = sErrorMessage;
}
}
|