This is a migrated thread and some comments may be shown as answers.

WCF - The server method 'LoadClients' failed

1 Answer 102 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Neelima
Top achievements
Rank 1
Neelima asked on 01 Mar 2012, 06:26 PM
I followed the below tutorial link to populate a RadComboBox using WCF service.
This works fine on localhost but when I deploy it on the server I'm getting an error "The server method 'LoadClients' failed"  whenever this service is called.

http://www.telerik.com/help/aspnet-ajax/combobox-load-on-demand-wcf-service.html


WebConfig:
<system.serviceModel>
        <behaviors>
            <endpointBehaviors>
                <behavior name="WCFClientsAspNetAjaxBehavior">
                    <enableWebScript/>
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
        <services>
            <service name="WCFClients">
                <endpoint address="" behaviorConfiguration="WCFClientsAspNetAjaxBehavior" binding="webHttpBinding" contract="WCFClients"/>
            </service>
        </services>
        <bindings>
 <webHttpBinding>  
  <binding name="webBinding">
      <security mode="Transport">
       </security
   </binding>
   </webHttpBinding>

WCFClients.svc:
<OperationContract()> _
Public Function LoadClients(ByVal context As RadComboBoxContext) As RadComboBoxData
 
    'The RadComboBoxData object contains all required information for load on demand:
    ' - the items
    ' - are there more items in case of paging
    ' - status message to be displayed (which is optional)
    Dim result As New RadComboBoxData()
    ' Dim connectionStr As String = Current.Session("ConnectionString").ToString
    Dim connectionStr As String = "MyConnectionString"
    Dim TransMgr As New TransmgrClientsDataContext(connectionStr)
 
    'Get all items from the Customers table. This query will not be executed untill the ToArray method is called.
    Dim allCustomers = From c In TransMgr.Clients _
        Order By c.LastNm _
        Select customer = New RadComboBoxItemData With _
        {.Text = c.LastNm & " " & c.FirstNm, .Value = Convert.ToString(c.Clnt_No)}
 
    'In case the user typed something - filter the result set
    If Not [String].IsNullOrEmpty(context.Text) Then
        allCustomers = allCustomers.Where(Function(item) item.Text.StartsWith(context.Text))
    End If
    'Perform the paging
    ' - first skip the amount of items already populated
    ' - take the next 10 items
    Dim customers = allCustomers.Skip(context.NumberOfItems).Take(10)
 
    'This will execute the database query and return the data as an array of RadComboBoxItemData objects
    result.Items = customers.ToArray()
 
 
    Dim endOffset As Integer = context.NumberOfItems + customers.Count()
    Dim totalCount As Integer = allCustomers.Count()
 
    'Check if all items are populated (this is the last page)
    If endOffset = totalCount Then
        result.EndOfItems = True
    End If
 
    'Initialize the status message
    result.Message = [String].Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset, totalCount)
 
    Return result
 
End Function

  

aspx:

<script type ="text/javascript" >
    function validateCombo(source, args) {
        args.IsValid = false;
        var combo = $find(source.controltovalidate);
        var selectedItem = combo.get_selectedItem();
        if (selectedItem) {
            var value = selectedItem.get_value();
            if (value > 0) {
                args.IsValid = true;
            }
        }
    }
</script>
<telerik:RadComboBox runat="server" ID="rcbClients" Height="100px" EnableLoadOnDemand="true"
    ShowMoreResultsBox="true" EnableVirtualScrolling="true" AllowCustomText="false"
    EmptyMessage="Type lastname ...">
    <WebServiceSettings Path="WCFClients.svc" Method="LoadClients" />
</telerik:RadComboBox>
<asp:CustomValidator ID="cvClients" runat="server" ClientValidationFunction="validateCombo"
    SetFocusOnError="true" ErrorMessage="Please select a client from Dropdown" ControlToValidate="rcbClients">*
</asp:CustomValidator>


Thank you for your help!!

1 Answer, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 06 Mar 2012, 05:29 PM
Hi,

In order to troubleshoot this issue, try to monitor your traffic using Fiddler Cap and provide us the log file. Also please add the following lines in your web config file so we could get more details about the error being received:
<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>

The experienced problem might be caused by an authentication issue, so try to grand access to your web service using the following configuration:
Copy Code
<location path="">  
    <system.web>      
        <authorization>
            <allow users="*" />      
        </authorization>  
    </system.web>
</location>

You should specify your web service in the path attribute of the location tag.

Greetings,
Dimitar Terziev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ComboBox
Asked by
Neelima
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
Share this question
or