Please help, frustrated with calling C# web service with code.

O

OMAF-Terry

I've posted a few messages here and looked at countless posts but not able to
find a complete solution. I have everything working the way I want all I need
now is to call my web service when the page loads.

One suggestions was to use the data connection method and have it populate
when the form loads but I'm not seeing how to do that when I have a parameter
(System.Environment.UserName) that needs to be passed to the service in order
for it to return value.

Here is the web service method I need to call:

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 username using Active Directory.";
}

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

Anyone????
 
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.Se­rverVariables["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
 
B

B King

Basically to recap what is happening is that you use a rule to set the
value of the query string for your web service. then you execute the
query then you set a fields value retreiving the result of the query ..
its a 3 step process.
 

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