In my Infopath form,I have multiple "FIND" buttons.Each of these "FIND" buttons is used to fetch user details from the ADS.
Example-I enter my employee ID and click on the first "Find" button.It fetches my details from ADS based on my employee ID.
Similarly I also use another "FIND" button to search the name of my superior based on his first or last name.So if I enter "A" and click the "FIND" button,I get a list of names from ADS starting from "A" which I populate into a listbox.Then I select my superior name from the shortlisted names in the list box.
To achieve this I use Managed code.On the "FIND" button's onclick event, I first tried to call the function containing the logic(involving DirectorySearcher class to access the ADS).
But it simply throws an Unhandled exception even when previewing stating
System.Security.SecurityException
Security error.
at CashPaymentVoucher.CashPaymentVoucher.FindADSUsers(String PS_Number)
at CashPaymentVoucher.CashPaymentVoucher.CTRL45_5_OnClick(DocActionEvent e) in e:\1cpv\cashpaymentvoucher\formcode.cs:line 57
at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
While debugging I noticed that as soon as the function call is made, this exception is thrown. So even while previewing the form,I get this error on button click.
So I decided to use a webservice.It works fine on previewing the form and does not throw any error on button click.It fetches the details on button click(while previewing).
But once I publish the firm in a SharePoint Form Library,It threw me the following error....
Infopath cannot complete this action because of an error in the form's code
Request for the permission of type System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
at System.Security.CodeAccessSecurityEngine.CheckHelper(PermissionSet grantedSet, PermissionSet deniedSet, CodeAccessPermission demand, PermissionToken permToken)
at System.Security.CodeAccessSecurityEngine.Check(PermissionToken permToken, CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 checkFrames, Int32 unrestrictedOverride)
at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Demand()
at System.Net.HttpRequestCreator.Create(Uri Uri)
at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
at System.Net.WebRequest.Create(Uri requestUri)
at System.Web.Services.Protocols.WebClientProtocol.GetWebRequest(Uri uri)
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebRequest(Uri uri)
at System.Web.Services.Protocols.SoapHttpClientProtocol.GetWebRequest(Uri uri)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at CashPaymentVoucher.WebReference.Service1.FindADSUsers(String PS_Number) in E:\1CPV\CashPaymentVoucher\Web References\WebReference\Reference.cs:line 37
at CashPaymentVoucher.CashPaymentVoucher.CTRL45_5_OnClick(DocActionEvent e) in e:\1cpv\cashpaymentvoucher\formcode.cs:line 56
at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
But this problem does not happen when I preview the form.It happens when I publish it in SPS form library.
My SharePoint server is deployed in port number 8080 while my webservice runs in port number 9090.Is the problem due to difference in Port number??? because the error message points to "at CashPaymentVoucher.WebReference.Service1.FindADSUsers(String PS_Number) in E:\1CPV\CashPaymentVoucher\Web References\WebReference\Reference.cs:line 37
".This Reference.cs file contains the URL of the webservice.
Can you please help me????