Webservice that returns user Name

R

Rhonda

Hi all,

I am new to Infopath and need a little help. I have a form that we want to
fill the Seller Name information from Active Directory. I wrote a webservice
that returns the information as a string based on the current logged in user.

public string GetUser()
{
string sUser = HttpContext.Current.Request.ServerVariables["LOGON_USER"];
int iPos = sUser.IndexOf("\\");
string strUserName = sUser.Substring(iPos+1, sUser.Length-(iPos+1));
try
{
string ADServer = "server.com";
string ADPath= "LDAP://sv.NA.invmc.com/DC=SV,DC=NA,DC=sv,DC=com";
string ADUser = "Username";
RegistryKey SPSUserKey =
Registry.LocalMachine.OpenSubKey("Software\\SV\\SPS");
string ADPassword = SPSUserKey.GetValue("ADPassword").ToString();
DirectoryEntry de = new
DirectoryEntry(ADPath,ADUser,ADPassword,AuthenticationTypes.Secure);
DirectorySearcher deSearch = new DirectorySearcher();
deSearch.SearchRoot = de;
deSearch.Filter = "(&(objectClass=user)(sAMAccountName=" + strUserName +
"))";
deSearch.SearchScope = SearchScope.Subtree;
SearchResult result = deSearch.FindOne();

if(result == null)
{
return "Error finding user " + strUserName + " using Active Directory.";
}
DirectoryEntry dirEntry = result.GetDirectoryEntry();
string sFirstName = dirEntry.Properties["givenName"].Value.ToString();
string sLastName = dirEntry.Properties["sn"].Value.ToString();
string sFullName = sFirstName + " " + sLastName;

return sFullName;

}
catch(Exception ex)
{
return ex.ToString();
}
}

The webservice seems to return the correct information when I run it from VS
but when I add it to the Infopath form and try to access it, it doesn't seem
to return anything. It always come back as null. I don't know what I am
doing wrong. Any help would be appreciated. Here is my script code for
infopath. This is happening on the onload event.

var oData = XDocument.DataObjects.Item("GetUser");

oData.DOM.setProperty("SelectionNamespaces",'xmlns:dfs="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:s0="http://tempuri.org/GetUserInfo/Service1"');

oData.Query();

var queryValue =
oData.DOM.selectSingleNode("/dfs:GetUserResponse/dfs:queryFields/s0:GetUser/s0:GetUserResult");
XDocument.UI.Alert("queryValue:"+ queryValue);
if (queryValue != null)
{
XDocument.DOM.selectSingleNode("/my:myFields/my:txtSeller").text =
queryValue.text;
}



Thanks a ton.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top