Looking for sample code for calling web service

O

OMAF-Terry

Below is my method (C#). Could someone please post the code to call the web
service onLoad of an InfoPath form?

=============================================

[WebMethod (Description="Get the full name of the InfoPath form user.")]
public string getCurrentUserFullName(string localUserName)
{
DirectoryEntry entryFullName = new
DirectoryEntry("LDAP://ou=people,dc=something,dc=on,dc=ca");
DirectorySearcher dsFullName = new DirectorySearcher(entryFullName);
dsFullName.Filter = "(SAMAccountName=" + localUserName + ")";
dsFullName.PropertiesToLoad.Add("givenName");
dsFullName.PropertiesToLoad.Add("sn");
SearchResult resultFullName = dsFullName.FindOne();

if(resultFullName == null)
{ return "Error finding username using Active Directory. Please
contact the help desk.";
}

string strCurrentUserFullName =
resultFullName.Properties["givenName"][0].ToString() + " " +
resultFullName.Properties["sn"][0].ToString();
return strCurrentUserFullName;
}
 
S

Scott L. Heim [MSFT]

Hi,

The easiest way to accomplish this is to setup your web service as a
"Secondary Data Connection" and when you walk through the wizard, the last
screen provides an option to automatically get the data upon load of the
form.

I hope this helps!
Best Regards,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
O

OMAF-Terry

Scott, thanks for the reply.

I have another data connection using this method that works great but I need
to pass System.Environment.UserName to the service which returns a value.

Not sure how I would accomplish that using the add data connection method or
am I missing something?
 
S

Scott L. Heim [MSFT]

Hi,

If I understand what you need, you should be able to do something like the
following:

- Add the web service as a data connection (receive data)
- In the OnLoad event, set a variable to the result of
System.Environment.UserName
- You can then use the GetDOM method to get a reference to the secondary
data source and use code to pass in the variable

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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