Implementing WebSevice with OpenAccess inside

Thread is closed for posting
10 posts, 0 answers
  1. tmlipinski
    tmlipinski avatar
    131 posts
    Member since:
    Dec 2006

    Posted 24 Feb 2009 Link to this post

    Hi,

    I have 2 projects:
    - WebService - to perform all DAL and BLL functions
    - web site - as a front end for this WebService

    And some questions:

    1. Data types conflict.
    WebService has its asmx created by your wizard. It contains a method GetAllOrders that returns ChangeSet::

     

        using Telerik.OpenAccess;   
        namespace MyServiceSpace   
        {  
        [WebService(Namespace="MyServiceSpace")]   
        public class MyServiceClass : System.Web.Services.WebService   
        [WebMethod]   
        public ObjectContainer.ChangeSet GetAllOrders()  
        .... 

    In the web site there is a Web Reference to this service - named MyServiceRef. And I try to execute GetAllOrders:
     

        using Telerik.OpenAccess;  
        ......  
        MyServiceRef.MyServiceClass srv = new MyServiceRef.MyServiceClass();   
        ObjectContainer.ChangeSet res = srv.GetAllOrders(); 

    Oops - I get a compiler message: Cannot convert 'MyServiceRef.ChangeSet' to 'Telerik.OpenAccess.ObjectContainer.ChangeSet'

    Why? How to avoid it? If I change the type of "res" to "object" it is performed successfully.

    2. How to use ObjectProvider's ResultMethod type: Request?
    As I understand this method is intended to make ObjectProvider (and ObjectView and RadGrid supplied with it) working with a WebService. So I've written (copying from your demo):
     

        ObjectProvider provider = new ObjectProvider();   
        provider.BaseType = typeof(PersistentClasses.Order);    // the definition of PersistentClasses is available in both projects   
        provider.RequestName = "MyServiceClass.GetAllOrders";   
        provider.ResultMethod = Telerik.OpenAccess.ObjectProvider.ResultMethodType.Request;
       
        provider.ResultName = "Orders";   
        provider.ObjectContextProviderTypeName = "???.MyObjectContainerProvider";    // here is the issue - see below   
        Telerik.OpenAccess.ObjectView view = new Telerik.OpenAccess.ObjectView();   
        view.ObjectProvider = provider;  
        view.RootType = typeof(PersistentObjects.Order); 

    My WebService contains MyObjectContainerProvider class that is automatically generated by your tool (I've changed its default name). As I understand it should be possible to use this class, not a provider class defined in the web site project (another way it doesn't make sense to use the web service). But whatever I put instead of "???" I get a message that this provider cannot be found. Is it possible to use this provider from the web service - and how to declare it?

    3. Using ObjectContainer - "best practices".
    In your demo you use the method described above. But in the sample code from the Code Library (Working with Disconnected API using ObjectContainer) you use just another way. In terms of my example it would be:

     

        MyServiceRef.MyServiceClass srv = new MyServiceRef.MyServiceClass();   
        ObjectContainer container = new ObjectContainer();  
        container.Apply(srv.GetAllOrders());  
        RadGrid1.DataSource = container.Extent(typeof(PersistentClasses.Order)); 

    What are the differences between these two methods? What are pros and cons in both cases?

    Regards
    Tomasz

     

     

     

     

     

     

  2. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 27 Feb 2009 Link to this post

    Hi tmlipinski,
    You are getting the compile error because the web service import did generate a proxy object. The ChangeSet has a specific ctor to convert this. You can use:

    ObjectContainer.ChangeSet cs = new ObjectContainer.ChangeSet(srv.GetAllOrders());

    The generated methods for ObjectProvider and ObjectContainerProvider are there to let our wizards generate code that is working without any changes.

    If you want to implement your own way you can use the ChangeSet directly. That makes also more sense because your code might be less complicated and better understandable.

    Your code under (3) is the right one and with the indirection that I mentioned above it should work.

    If you have more questions or want more details about our generated classes, please feel free to contact us again.

    Kind regards,
    Jan Blessenohl
    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. tmlipinski
    tmlipinski avatar
    131 posts
    Member since:
    Dec 2006

    Posted 27 Feb 2009 Link to this post

    Hi,

    1. OK. It works. You should point it out in the documentation, examples and demos. (For those, who don't know what's going on with this proxy - see here). But it's an additional cost, alas - because it's a copy constructor. 

    2. You haven't understand me. The key question is: is the ResultMethod.Request mode designed for driving ObjectProvider -> ObjectView -> RadGrid directly by a WebService, i.e. by setting the name of a method from this WS (RequestName) and the name of the object container provider also from this WS (ObjectContextProviderTypeName)?
    If "yes": how to construct the ObjectContextProviderTypeName value in my case?
    If "no": what is the anticipated usage of ResultMethod.Request?

    3. This question is valid only if the answer for the above question is: "yes". In this case we have two methods for supplying RadGrid with data from a WebService. What is the difference between them? When to use one of them and when - another one?

    Regards
    Tomasz
  4. Dimitar Kapitanov
    Admin
    Dimitar Kapitanov avatar
    632 posts

    Posted 06 Mar 2009 Link to this post

    Hello tmlipinski,
    Some more clarification to your question #2 and #3:

    #2 - you have to include the assembly name as well, like "OpenAccessNorthwindMapping.ObjectScopeProvider1, OpenAccessNorthwindMapping" where the first part is the class name, and the second is the assembly name.

    However I must add that this code is better to be generated with our wizards instead of manually crafting it.

    #3 From our perspective you should use the second one - using ObjectContainer allows to implement in the correct manner the N-tier application scenario. You can use the ObjectContainer as a disconnected representation of the datastore that can transport data in the upper layers. On the other hand ObjectView is derived from the BindingSource class, which is a concrete Windows Forms implementation, thus is is not suitable for all types of scenarios.

    Regards,
    Dimitar Kapitanov
    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.
  5. tmlipinski
    tmlipinski avatar
    131 posts
    Member since:
    Dec 2006

    Posted 06 Mar 2009 Link to this post

    Hello,

    Thanks for the patience :-)

    #3 - OK (although it should be clarified in the documentation and demos)
    #2. I'm sorry but it still doesn't work. I've even done a trick: I've put in the code a direct call to some WS's method, stepped into it, checked under debugger the full name of the ObjectScopeProvider class and copied it into client-side parameters. And there is still the message: "Object Provider: Helper type xxx not found". I know that it's a kind of theoretic consideration (in the context of #3 explanation) but let's clarify it to the very end.

    Regards
    Tomasz
  6. Dimitar Kapitanov
    Admin
    Dimitar Kapitanov avatar
    632 posts

    Posted 06 Mar 2009 Link to this post

    Hi tmlipinski,
    But do you have the helper class defined and working indeed? Do you have a reference to the enhanced assembly that contains the class in your references section of the .config file?

    All the best,
    Dimitar Kapitanov
    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.
  7. tmlipinski
    tmlipinski avatar
    131 posts
    Member since:
    Dec 2006

    Posted 06 Mar 2009 Link to this post

    Hi,
    This helper class is defined and working - but at the WS side, of course. It is not defined or directly referenced from the client side. If it should be - wouldn't it be a contradiction with the idea of WS?

    Regards
    Tomasz
  8. Dimitar Kapitanov
    Admin
    Dimitar Kapitanov avatar
    632 posts

    Posted 06 Mar 2009 Link to this post

    Hi tmlipinski,
    Exactly that is the case. What I wanted to point at is that this operation is perfectly doable on the WS side and not on the client side. The reference could not be resolved on the remote side because you do not have the assembly loaded in the process, and if had it, why using service at all right? My suggestion supposed that you want to do it on the server side, but obviously that was not the case.

    Greetings,
    Dimitar Kapitanov
    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.
  9. tmlipinski
    tmlipinski avatar
    131 posts
    Member since:
    Dec 2006

    Posted 06 Mar 2009 Link to this post

    Hi,

    If so, let me summarize - correct me if I'm wrong:
    - ResultMethodType.Request has nothing to do with WebServices
    - it is designed to supply data by a named method of a named class from one of client's assemblies
    Unfortunately, in your demos this method comes from a WebService.. which in this case is not a real WebService but just one of the assemblies. And that is why all that mess has come from.

    Regards
    Tomasz
  10. Dimitar Kapitanov
    Admin
    Dimitar Kapitanov avatar
    632 posts

    Posted 09 Mar 2009 Link to this post

    Hello tmlipinski,
    The functionality in question can be used as a part of a WebService solution when you implement the WS proxies yourself. What we can do is to prepare extensive examples and documentation regarding this functionality soon after the Q1 2009 release. Hope that helps.

    All the best,
    Dimitar Kapitanov
    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.
Back to Top