Common, someone must know. Web services and Infopath

T

terry.dupuis

I've posted numerous times, searched, searched, searched and can't seem
to get an answer on this.

I have a C# web service that I want to query when infopath form starts.
The web method takes one parameter that is the username of the person
using the form (System.Environment.UserName).

That's all I want but I can't figure out how to do this in onLoad with
C#.

Someone suggested creating the 2nd data source and having the text
field populate onLoad but how do you do that when you need to submit
parameter first?

ANYONE??? Can you please provide code.


Webservice:
=============================================
[WebMethod (Description="Get the full name of the form user.")]
public string getCurrentUserFullName(string localUserName)
{
DirectoryEntry entryFullName = new
DirectoryEntry("LDAP://ou=people,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 user " + localUserName + " in Active
Directory.";
}

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

B King

One way to do it would be to provide the username to your webservice by
adding a new function in your service:

public string GetUserName()
{
string sUser =
HttpContext.Current.Request.ServerVariables["LOGON_USER"];
int iPos = sUser.IndexOf("\\");
string strUserName = sUser.Substring(iPos+1,
sUser.Length-(iPos+1));
return strUserName;
}


Then in the WebMethod you have above add:

string localUsername = GetUsername();



ANOTHER WAY:
GO to Tools > Data Connections and add your web service to Receive ..
Make sure in the last dialog you check off the box about automatically
retreiving the data whent he form loads.

if you are already succesfully filling out a control with the Username
and say the control is called Username go to its properties and choose
Rules button.
1. Click Add
2. Click Set Condition
3. Username is not blank
4. Add Action
5. Set a fields Value
6. Click the button next to the filed value and choose the
getCurrentUserFullName from the Data Drop down
7. UNder queryFileds drill down to localUserName click OK
8. UNder Value field choose the field in the Main source that has the
Username in it Click OK

9. Add another Action this time selecting Query Using a Data Connection
and select getCurrentUserFullName from the list and click OK

10. Add Action again .. this time Set a fields value
11. In the field click the button to select the getCurrentUserFullName
dataFields tree pick getCurrentUserFullNameResult

Now close all dialogs and preview your form.


HTH,

Brad King
 

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