This is a simple method call to the Xtend61 API. I am using Visual Studio 2008 & a simple legacy web service connection (Web Reference). To test I used a simple web form that has a button to invoke the call and some linq code to parse the response xml. I used the GetEmployeesByKey() method to get name and phone number.
You have to add a web reference (right-click & add Web Reference) to the web service. The target url is http://<webserver>/vision/VisionWS.asmx. You will have to authenticate to the target server. VS does a lot of work for you creating a proxy class which you’ll see under App_WebReferences. It also puts a small key reference in you web.config <appSettings>. That change and the proxy class will need to be copied to your production setup along with the new page.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Net;
using System.Xml.Linq;
public partial class Vision6Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Security.Principal.WindowsIdentity user = System.Security.Principal.WindowsIdentity.GetCurrent(); //operator
if (IsPostBack)
PagePostback();
else
PageInitialPost();
}
private void PageInitialPost()
{
Page.SetFocus(txtEmpNum);
}
private void PagePostback()
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Utilities.hasNoData(txtEmpNum)) // check for no data inbound
{
lblMessage.Text = "Missing Employee Number";
return;
}
string UserID = "someUser";
string Password = "pwd";
string Domain = "YourDomain";
string DatabaseDescription = "Vision6"; // from Web link - see doc
string IntegratedSecurity = "Y"; // match ID setting in system
vision6.DeltekVisionOpenAPIWebService proxy = new bwvision6.DeltekVisionOpenAPIWebService(); //Web Reference Proxy
// Setup Parms
string ConnInfoXml = @"<VisionConnInfo><databaseDescription>" + DatabaseDescription + @"</databaseDescription>";
ConnInfoXml += @"<userName>" + UserID + @"</userName>";
ConnInfoXml += @"<userPassword>" + Password + @"</userPassword>";
ConnInfoXml += @" <integratedSecurity>" + IntegratedSecurity + @"</integratedSecurity>";
ConnInfoXml += @"</VisionConnInfo>";
string Keys = txtEmpNum.Text.Trim(); // inbound Employee ID from webpage
string RecordDetail = "Primary"; // send only primary record back
// pass credentials on call - should use some dedicated account
proxy.UseDefaultCredentials = true;
proxy.Credentials = new NetworkCredential(UserID, Password, Domain);
string WSResponse = proxy.GetEmployeesByKey(ConnInfoXml, Keys, RecordDetail);
// check empty response
if (WSResponse == @"<RECS></RECS>" || Utilities.hasNoData(WSResponse))
{
string sEmp = txtEmpNum.Text.Trim();
clearAll();
lblMessage.Text = "Employee " + sEmp + " Not Found";
return;
}
string sXML = preProcessXML(WSResponse);
lblResults.Text = parseXML(sXML, "FirstName");
lblResults.Text += " " + parseXML(sXML, "LastName");
lblResults.Text += " " + parseXML(sXML, "WorkPhone");
lblResults.Text += @" x/" + parseXML(sXML, "WorkPhoneExt");
}
private string parseXML(string xml, string targetField)
{
string sReturn = "";
XElement ele = XElement.Parse(xml);
try
{
sReturn = ele.Elements().Descendants(targetField).First().Value;
}
catch (NullReferenceException nex) // drop nulls default to empty string
{
string sDrop = nex.ToString();
}
catch (Exception ex)
{
string sDrop = ex.ToString(); // you can throw a new exception or handle this
}
return (sReturn);
}
private string preProcessXML(string sXML)
{
sXML = sXML.Replace(">", ">");
sXML = sXML.Replace("<", "<");
return (sXML);
}
private void clearAll()
{
txtEmpNum.Text = "";
lblMessage.Text = "";
lblResults.Text = "";
Page.SetFocus(txtEmpNum);
}
protected void btnClear_Click(object sender, EventArgs e)
{
clearAll();
}
}
