WebMethod Signature

8 posts, 0 answers
  1. Mike
    Mike avatar
    4 posts
    Member since:
    Mar 2008

    Posted 06 Jul 2009 Link to this post

    I am trying to determine the correct signature for web methods called by the XmlHttpPanel (version 2009.2.701.35).

    If I use the signature: 
    string MyWebMethod(object sender, object args) , 

    both sender and args come in as null. If I look at the source for the page, I can see the following javascript:

    WebForm_InitCallback();Sys.Application.add_init(function() {
    $create(Telerik.Web.UI.RadXmlHttpPanel, {"_uniqueId":"ctl00$ContentBody$RadXmlHttpPanel1","clientStateFieldID":"ctl00_ContentBody_RadXmlHttpPanel1_ClientState","loadingPanelID":"","value":"922e2baf-696a-de11-baa9-005056c00008","webMethodName":"MyWebMeathod","webMethodPath":"/MyTestApp/Services/SampleService.svc"}, {"responseEnd":OnRadXmlHttpClientResponseEnd}, null, $get("ctl00_ContentBody_RadXmlHttpPanel1"));
    });

    I have also tried having the signature:
    void MyWebMethod(object sender, RadXmlHttpPanelEventArgs e)
    but I just get a message along the lines of 'The web method 'MyWebMethod' failed'

    I am expecting to get that value passed to me in the args (it's the Value for my XmlHttpPanel), either with or without a sender.
  2. Tervel
    Admin
    Tervel avatar
    1337 posts

    Posted 09 Jul 2009 Link to this post

    Hi Mike,

    The default example of the RadXmlHttpPanel demonstrates how to use a web service:
    http://demos.telerik.com/aspnet-ajax/xmlhttppanel/examples/default/defaultcs.aspx

    What you need to do is

    1. Set the web service name and path to the control itself, e.g:

    <telerik:RadXmlHttpPanel runat="server" ID="XmlHttpPanelWS" Value="3" OnClientResponseEnd="OnClientResponseEnd" WebMethodPath="XmlHttpPanelWebService.asmx"
    WebMethodName="GetCustomersByCountryXmlHttpPanel">


    2. Provide a .asmx file in the same folder, which "points to the web service.
    Here is the content of this example's asmx file:
    <%@ WebService Language="C#" CodeBehind="~/App_Code/ToolTipWebService.cs" Class="ToolTipWebService" %>

    3. Provide the actual web-service implementation (in the example's case the cs file is located in the /App_Code folder. The method accepts one argument only, and is marked as web-method
     [WebMethod]
        public string GetCustomersByCountryXmlHttpPanel(object context)
        {
            return this.GetCustomersByCountry(context, "~/XmlHttpPanel/Examples/Default/UserControls/");       
        }


    For more information, please examine the ~//App_Code/ToolTipWebService.cs in the Telerik RadControls installation on your computer.


    Best regards,
    Tervel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Carl
    Carl avatar
    20 posts
    Member since:
    Nov 2008

    Posted 15 Jul 2009 Link to this post

    Hi Tervel,

    I have setup an example using a WCF service (as shown in the demo video). I can get the basic example to work, but when I add a context object to my WCF method and attempt to cast it to the IDicitionay<string, object> I get an InvalidCastException.

    Can you help at all please? I am using version 2009.2.701.20.

    Thanks v much, Carl
  5. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 21 Jul 2009 Link to this post

    Hello Carl,

    From the information provided we could not find a solution to your project. Can you please open a new support ticket and send us the source code of your sample project (and perhaps clear reproduction steps), so we can reproduce the error on our side? Once we have a better view over the problem, it would be easier to resolve it.


    Best wishes,
    Pero
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Carl
    Carl avatar
    20 posts
    Member since:
    Nov 2008

    Posted 03 Sep 2009 Link to this post

    Hi there,

    Excuse the late reply. I have got this working using a ScriptService. What I couldn't get to work is the following; the method is called but the context object is not a dictionary:

       [ServiceContract] 
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
        public class CommunicatorService 
        { 
            [OperationContract] 
            public string DoWork(object context) 
            { 
                IDictionary<stringobject> contextDictionary = (IDictionary<stringobject>) context; 
                string value = ((string) contextDictionary["Value"]); 
     
                return "You selected " + value; 
            } 
        } 

    With system.servicemodel in app.config roughly this:

        <behaviors> 
          <endpointBehaviors> 
            <behavior name="Test.CommunicatorServiceAspNetAjaxBehavior"
              <enableWebScript /> 
            </behavior> 
          </endpointBehaviors> 
        </behaviors> 
        <services> 
          <service name="Test.CommunicatorService"
            <endpoint address="" behaviorConfiguration="Test.CommunicatorServiceAspNetAjaxBehavior" 
             binding="webHttpBinding" contract="Test.CommunicatorService" /> 
          </service> 
        </services> 
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 


    The alternative Script Service works without issue:

        [ScriptService] 
        public class NewTest : WebService 
        { 
            [WebMethod] 
            public string DoWork(object context) 
            { 
                IDictionary<stringobject> contextDictionary = (IDictionary<stringobject>)context; 
                string value = ((string)contextDictionary["Value"]); 
     
                return "You selected " + value; 
            } 
        } 

    Is it possible to get the contextDictionary using a WCF service? Is it just that I've configured this incorrectly?

    Thanks, Carl
  7. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 08 Sep 2009 Link to this post

    Hi Carl,

    As far as I can see everything is configured correctly in your application. I myself created similar application and tried to pass the value to an AJAX Enabled WCF service but without any success.

    The fact is we could not figure out why the value is not passed to the WebService method. We will continue researching this issue and in case we find something we will notify you. Until then our recommendation is to use ScriptService.

    Let us know if you have other questions. 


    Greetings,
    Pero
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Patrick McDavid
    Patrick McDavid avatar
    4 posts
    Member since:
    Feb 2010

    Posted 27 Apr 2010 Link to this post

    I'm having this same problem

            <telerik:RadToolTipManager ID="rttmPersonToolTip" RelativeTo="Element" Animation="Fade" Position="TopLeft" runat="server"
                <WebServiceSettings Path="/WebServices/RedwoodService.svc" Method="GetPersonToolTipContent" UseHttpGet="true" /> 
            </telerik:RadToolTipManager> 

    +



            [OperationContract] 
            [WebGet] 
            public string GetPersonToolTipContent(object value) 
            { 
     
                return "asdf"
            } 

    this returns my asdf string no problem, but "value" is always null...




  9. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 29 Apr 2010 Link to this post

    Hello Patrick McDavid,

    Please, note, that the object context is not just a simple variable which can be named, it is actually parameter used in the RadToolTipManager's code when passing.reading.loading the data and thus it should stay with the same name. As you see, the WebService loading is done almost without any code from the developer - all this code resides in the RadToolTipManager's source code and unfortunately for this case you cannot optionally name because in the source code actually exists the object context. Furthermore, what you pass is not only a simple parameter but as you see form the cast this is a whole dictionary and thus it is also logically invalid to call it simply parameter. We also emphasized on the needed structure of the WebService in the description of the demo below:

    http://demos.telerik.com/aspnet-ajax/tooltip/examples/webservice/defaultcs.aspx

    This being said, all you need to do to make the things work is to use the context as shown below:

    public string GetPersonToolTipContent(object context)  
          {  
      
              return "asdf";  
          }  

    Kind regards,
    Svetlina
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017