returning strongly typed dataset from web service

Discussion in 'ASP .Net Web Services' started by N. Shehzad, Mar 2, 2007.

  1. N. Shehzad

    N. Shehzad Guest

    All,
    I have a webservice webmethod which does returns a strongly typed dataset
    called MyStronglyTypedDataSet correctly.

    On the client side, when I cast the dataset to my strongly typed dataset, it
    throws the following error "Cannot convert type
    ClientConsumer.localhost.MyStronglyTypedDataSet" to
    "MyNameSpace.WebServices.MyStronglyTypedDataSet'

    If I cast it as a regular dataset on client side, it works fine, but that
    defeats the whole purpose of having strongly typed DS in first place.

    I am using a web reference from the client application to the web service,
    and also reference to the StronglyTpedDataSet dll that I created using SDK
    Command Prompt

    What am I doing wrong?
     
    N. Shehzad, Mar 2, 2007
    #1
    1. Advertising

  2. "N. Shehzad" <> wrote in message
    news:...
    > All,
    > I have a webservice webmethod which does returns a strongly typed dataset
    > called MyStronglyTypedDataSet correctly.
    >
    > On the client side, when I cast the dataset to my strongly typed dataset,
    > it
    > throws the following error "Cannot convert type
    > ClientConsumer.localhost.MyStronglyTypedDataSet" to
    > "MyNameSpace.WebServices.MyStronglyTypedDataSet'
    >
    > If I cast it as a regular dataset on client side, it works fine, but that
    > defeats the whole purpose of having strongly typed DS in first place.
    >
    > I am using a web reference from the client application to the web service,
    > and also reference to the StronglyTpedDataSet dll that I created using SDK
    > Command Prompt
    >
    > What am I doing wrong?


    Why are you referencing the dll from the server? The client and server
    classes have no direct relation to each other.

    What happens if you create a new project and use Add Web Reference to add a
    reference to your web service? Isn't that enough to get you your
    strongly-typed dataset on the client side?

    John

    P.S. I just tried it myself, and it seems to work. Just keep in mind that
    you've got a server-side DataSet and a client-side proxy DataSet, and that
    the two types are unrelated.
     
    John Saunders, Mar 3, 2007
    #2
    1. Advertising

  3. N. Shehzad

    Scott M. Guest

    Why are you trying to cast an object into the type that it already is? You
    don't need to cast at all here.

    Your client code should simply be:

    Dim receivedDataSet As MyStronglyTypedDataSet = webService.webMethodCall()

    If your web method is returing a type of "MyStronglyTypedDataSet", all you
    need to do is set up a pointer (not a new instance) to that returned object.
    That pionter needs to be declared as being the same type (or a type that
    your returned object derives from).

    Now, having said all of this. IMHO you shouldn't be returning a platform
    specific object from a web service in the first place. That defeats the
    purpose of a web service. I would recommend returning the XML
    representation of the strongly typed DataSet from your web service, rather
    than the object itself. This keeps your application open to the possibility
    of needing a heterogenius architecture in the future.



    "N. Shehzad" <> wrote in message
    news:...
    > All,
    > I have a webservice webmethod which does returns a strongly typed dataset
    > called MyStronglyTypedDataSet correctly.
    >
    > On the client side, when I cast the dataset to my strongly typed dataset,
    > it
    > throws the following error "Cannot convert type
    > ClientConsumer.localhost.MyStronglyTypedDataSet" to
    > "MyNameSpace.WebServices.MyStronglyTypedDataSet'
    >
    > If I cast it as a regular dataset on client side, it works fine, but that
    > defeats the whole purpose of having strongly typed DS in first place.
    >
    > I am using a web reference from the client application to the web service,
    > and also reference to the StronglyTpedDataSet dll that I created using SDK
    > Command Prompt
    >
    > What am I doing wrong?
    >
    >
     
    Scott M., Mar 4, 2007
    #3
  4. N. Shehzad,

    The main reason for the problem is that you are bundling the TypedDataset
    into an class library (dll). Please do not package the TypedDataset into an
    assembly.
    If you do that, you will end-up in the namespace conflicts.
    Try using the .xsd for TypedDataset at the
    Webservice side and the Client Side. I've used .xsd (instead of bundling .xsd
    inside assembly), it works. I could able to successfully pass the
    TypedDataset back-and-forth between webservice and client.

    Please let me know if this helps


    --
    Thanks & Regards,
    Sundar Narasiman


    "N. Shehzad" wrote:

    > All,
    > I have a webservice webmethod which does returns a strongly typed dataset
    > called MyStronglyTypedDataSet correctly.
    >
    > On the client side, when I cast the dataset to my strongly typed dataset, it
    > throws the following error "Cannot convert type
    > ClientConsumer.localhost.MyStronglyTypedDataSet" to
    > "MyNameSpace.WebServices.MyStronglyTypedDataSet'
    >
    > If I cast it as a regular dataset on client side, it works fine, but that
    > defeats the whole purpose of having strongly typed DS in first place.
    >
    > I am using a web reference from the client application to the web service,
    > and also reference to the StronglyTpedDataSet dll that I created using SDK
    > Command Prompt
    >
    > What am I doing wrong?
    >
    >
     
    Sundar Narasiman, Mar 5, 2007
    #4
  5. N. Shehzad

    N. Shehzad Guest

    Hi Sundar,
    I did create an .xsd schema first, and created a class file for that xsd
    schema using
    SDK Command prompt. How would I reference that class on the client side if I
    do not create a .dll library. Do I need to include that class on the client
    project as well?

    Thanks



    "Sundar Narasiman" wrote:

    > N. Shehzad,
    >
    > The main reason for the problem is that you are bundling the TypedDataset
    > into an class library (dll). Please do not package the TypedDataset into an
    > assembly.
    > If you do that, you will end-up in the namespace conflicts.
    > Try using the .xsd for TypedDataset at the
    > Webservice side and the Client Side. I've used .xsd (instead of bundling .xsd
    > inside assembly), it works. I could able to successfully pass the
    > TypedDataset back-and-forth between webservice and client.
    >
    > Please let me know if this helps
    >
    >
    > --
    > Thanks & Regards,
    > Sundar Narasiman
    >
    >
    > "N. Shehzad" wrote:
    >
    > > All,
    > > I have a webservice webmethod which does returns a strongly typed dataset
    > > called MyStronglyTypedDataSet correctly.
    > >
    > > On the client side, when I cast the dataset to my strongly typed dataset, it
    > > throws the following error "Cannot convert type
    > > ClientConsumer.localhost.MyStronglyTypedDataSet" to
    > > "MyNameSpace.WebServices.MyStronglyTypedDataSet'
    > >
    > > If I cast it as a regular dataset on client side, it works fine, but that
    > > defeats the whole purpose of having strongly typed DS in first place.
    > >
    > > I am using a web reference from the client application to the web service,
    > > and also reference to the StronglyTpedDataSet dll that I created using SDK
    > > Command Prompt
    > >
    > > What am I doing wrong?
    > >
    > >
     
    N. Shehzad, Mar 5, 2007
    #5
  6. "N. Shehzad" <> wrote in message
    news:...
    >
    > Hi Sundar,
    > I did create an .xsd schema first, and created a class file for that xsd
    > schema using
    > SDK Command prompt. How would I reference that class on the client side if
    > I
    > do not create a .dll library. Do I need to include that class on the
    > client
    > project as well?


    You don't need to do _anything_ to reference the class on the client side.
    Simply define your web service to return the strongly-typed dataset. Then
    use Add Web Reference in your client application to cause VS.NET to create
    the necessary proxy classes. One of those classes will be a client-side
    version of the server-side dataset. You will use that class on the client
    side.

    You will _never_ reference server-side classes on the client side. NEVER.

    John
     
    John Saunders, Mar 5, 2007
    #6
  7. N. Shehzad

    N. Shehzad Guest

    John,
    The problem is it does not create those client proxy classes for the dataset.
    When I add the web reference, it only creates the localhost reference that's
    all



    "John Saunders" wrote:

    > "N. Shehzad" <> wrote in message
    > news:...
    > >
    > > Hi Sundar,
    > > I did create an .xsd schema first, and created a class file for that xsd
    > > schema using
    > > SDK Command prompt. How would I reference that class on the client side if
    > > I
    > > do not create a .dll library. Do I need to include that class on the
    > > client
    > > project as well?

    >
    > You don't need to do _anything_ to reference the class on the client side.
    > Simply define your web service to return the strongly-typed dataset. Then
    > use Add Web Reference in your client application to cause VS.NET to create
    > the necessary proxy classes. One of those classes will be a client-side
    > version of the server-side dataset. You will use that class on the client
    > side.
    >
    > You will _never_ reference server-side classes on the client side. NEVER.
    >
    > John
    >
    >
    >
     
    N. Shehzad, Mar 5, 2007
    #7
  8. "N. Shehzad" <> wrote in message
    news:...
    > John,
    > The problem is it does not create those client proxy classes for the
    > dataset.
    > When I add the web reference, it only creates the localhost reference
    > that's
    > all


    Select the "localhost" reference in Solution Explorer. Turn on "Show All
    Files", either by clicking the icon at the top of the Solution Explorer, or
    else using Project->Show All Files. This will add a "+" sign in front of
    "localhost". Click the plus signs a few times, and you'll find a
    Reference.cs (or .vb) file. Open that, and you should see all of the proxy
    classes.

    OTOH, which version of VS.NET are you using? This may be a VS2005 feature.

    John
     
    John Saunders, Mar 5, 2007
    #8
  9. N. Shehzad

    N. Shehzad Guest

    Actually, I got it to work with one dataset, but if my webservice has
    multiple typed datasets, they do not show up as proxy xsd when I create or
    update the web reference.



    "John Saunders" wrote:

    > "N. Shehzad" <> wrote in message
    > news:...
    > >
    > > Hi Sundar,
    > > I did create an .xsd schema first, and created a class file for that xsd
    > > schema using
    > > SDK Command prompt. How would I reference that class on the client side if
    > > I
    > > do not create a .dll library. Do I need to include that class on the
    > > client
    > > project as well?

    >
    > You don't need to do _anything_ to reference the class on the client side.
    > Simply define your web service to return the strongly-typed dataset. Then
    > use Add Web Reference in your client application to cause VS.NET to create
    > the necessary proxy classes. One of those classes will be a client-side
    > version of the server-side dataset. You will use that class on the client
    > side.
    >
    > You will _never_ reference server-side classes on the client side. NEVER.
    >
    > John
    >
    >
    >
     
    N. Shehzad, Mar 5, 2007
    #9
  10. "N. Shehzad" <> wrote in message
    news:...
    > Actually, I got it to work with one dataset, but if my webservice has
    > multiple typed datasets, they do not show up as proxy xsd when I create or
    > update the web reference.


    See my other post, and which version of VS.NET are you using?

    John
     
    John Saunders, Mar 5, 2007
    #10
  11. N. Shehzad

    N. Shehzad Guest

    I am using vs 2005. It seems like vs 2005 only creates proxy xsd class for
    only one strongly typed dataset. if the webservice is using multiple
    datasets, it does not create multiple classes how can I make the reference
    map to reflect both classes?



    "John Saunders" wrote:

    > "N. Shehzad" <> wrote in message
    > news:...
    > > Actually, I got it to work with one dataset, but if my webservice has
    > > multiple typed datasets, they do not show up as proxy xsd when I create or
    > > update the web reference.

    >
    > See my other post, and which version of VS.NET are you using?
    >
    > John
    >
    >
    >
     
    N. Shehzad, Mar 5, 2007
    #11
  12. "N. Shehzad" <> wrote in message
    news:...
    >I am using vs 2005. It seems like vs 2005 only creates proxy xsd class for
    > only one strongly typed dataset. if the webservice is using multiple
    > datasets, it does not create multiple classes how can I make the reference
    > map to reflect both classes?


    Are both datasets used as return values?

    As an experiment, try changing the return type of the method whose dataset
    is being created in the proxy class with one of those that is not:

    Now a proxy for class A is being created:

    [WebMethod]
    A Method1(){return new A();}

    [WebMethod]
    B Method2(){return new B();}


    Change it to this and see what happens:

    [WebMethod]
    B Method1(){return new B();}

    [WebMethod]
    A Method2(){return new A();}

    John
     
    John Saunders, Mar 5, 2007
    #12
  13. N. Shehzad

    Scott M. Guest

    This is completely incorrect.

    A Typed DataSet is NOT an XSD. These are two different things.

    A Typed DataSet is a class that inherits from the DataSet class and has
    custom properties and methods created for it that model your specific data.
    This is a class and there is NO POSSIBLE WAY to not have it be part of an
    assembly (or a namespace for that matter).

    An XSD is an XML Schema Document, which is simply an XML Schema model of
    your empty DataSet.

    I have already provided the source and solution of your problem in my first
    reply.



    "Sundar Narasiman" <> wrote in
    message news:...
    > N. Shehzad,
    >
    > The main reason for the problem is that you are bundling the TypedDataset
    > into an class library (dll). Please do not package the TypedDataset into
    > an
    > assembly.
    > If you do that, you will end-up in the namespace conflicts.
    > Try using the .xsd for TypedDataset at
    > the
    > Webservice side and the Client Side. I've used .xsd (instead of bundling
    > .xsd
    > inside assembly), it works. I could able to successfully pass the
    > TypedDataset back-and-forth between webservice and client.
    >
    > Please let me know if this helps
    >
    >
    > --
    > Thanks & Regards,
    > Sundar Narasiman
    >
    >
    > "N. Shehzad" wrote:
    >
    >> All,
    >> I have a webservice webmethod which does returns a strongly typed dataset
    >> called MyStronglyTypedDataSet correctly.
    >>
    >> On the client side, when I cast the dataset to my strongly typed dataset,
    >> it
    >> throws the following error "Cannot convert type
    >> ClientConsumer.localhost.MyStronglyTypedDataSet" to
    >> "MyNameSpace.WebServices.MyStronglyTypedDataSet'
    >>
    >> If I cast it as a regular dataset on client side, it works fine, but that
    >> defeats the whole purpose of having strongly typed DS in first place.
    >>
    >> I am using a web reference from the client application to the web
    >> service,
    >> and also reference to the StronglyTpedDataSet dll that I created using
    >> SDK
    >> Command Prompt
    >>
    >> What am I doing wrong?
    >>
    >>
     
    Scott M., Mar 6, 2007
    #13
  14. N. Shehzad

    Scott M. Guest

    This is not correct.

    When you reference a web service, a proxy class for the web service is
    created on the web service consumer. BUT, proxies for all possible
    webMethod return types are NOT created.

    If the client will be receiving a strongly-typed DataSet, then the client
    will need this class referenced directly. This can be accomplished by the
    strongly-typed DataSet existing in a separate assembly that both the web
    service and it's consumer can both reference separately, or a copy of the
    class exists in another place for the client to reference.




    "John Saunders" <john.saunders at trizetto.com> wrote in message
    news:...
    > "N. Shehzad" <> wrote in message
    > news:...
    >>
    >> Hi Sundar,
    >> I did create an .xsd schema first, and created a class file for that xsd
    >> schema using
    >> SDK Command prompt. How would I reference that class on the client side
    >> if I
    >> do not create a .dll library. Do I need to include that class on the
    >> client
    >> project as well?

    >
    > You don't need to do _anything_ to reference the class on the client side.
    > Simply define your web service to return the strongly-typed dataset. Then
    > use Add Web Reference in your client application to cause VS.NET to create
    > the necessary proxy classes. One of those classes will be a client-side
    > version of the server-side dataset. You will use that class on the client
    > side.
    >
    > You will _never_ reference server-side classes on the client side. NEVER.
    >
    > John
    >
    >
     
    Scott M., Mar 6, 2007
    #14
  15. N. Shehzad

    Scott M. Guest

    No John, only the web service class gets a proxy created for it. Not the
    return types of the web method calls.


    "John Saunders" <john.saunders at trizetto.com> wrote in message
    news:...
    > "N. Shehzad" <> wrote in message
    > news:...
    >> John,
    >> The problem is it does not create those client proxy classes for the
    >> dataset.
    >> When I add the web reference, it only creates the localhost reference
    >> that's
    >> all

    >
    > Select the "localhost" reference in Solution Explorer. Turn on "Show All
    > Files", either by clicking the icon at the top of the Solution Explorer,
    > or else using Project->Show All Files. This will add a "+" sign in front
    > of "localhost". Click the plus signs a few times, and you'll find a
    > Reference.cs (or .vb) file. Open that, and you should see all of the proxy
    > classes.
    >
    > OTOH, which version of VS.NET are you using? This may be a VS2005 feature.
    >
    > John
    >
    >
     
    Scott M., Mar 6, 2007
    #15
  16. N. Shehzad

    Scott M. Guest

    XSD's can't be proxies as XSD's aren't classes. You are confusing Schemas
    with typed dataSets.


    "N. Shehzad" <> wrote in message
    news:...
    > Actually, I got it to work with one dataset, but if my webservice has
    > multiple typed datasets, they do not show up as proxy xsd when I create or
    > update the web reference.
    >
    >
    >
    > "John Saunders" wrote:
    >
    >> "N. Shehzad" <> wrote in message
    >> news:...
    >> >
    >> > Hi Sundar,
    >> > I did create an .xsd schema first, and created a class file for that
    >> > xsd
    >> > schema using
    >> > SDK Command prompt. How would I reference that class on the client side
    >> > if
    >> > I
    >> > do not create a .dll library. Do I need to include that class on the
    >> > client
    >> > project as well?

    >>
    >> You don't need to do _anything_ to reference the class on the client
    >> side.
    >> Simply define your web service to return the strongly-typed dataset. Then
    >> use Add Web Reference in your client application to cause VS.NET to
    >> create
    >> the necessary proxy classes. One of those classes will be a client-side
    >> version of the server-side dataset. You will use that class on the client
    >> side.
    >>
    >> You will _never_ reference server-side classes on the client side. NEVER.
    >>
    >> John
    >>
    >>
    >>
     
    Scott M., Mar 6, 2007
    #16
  17. "Scott M." <> wrote in message
    news:%...
    > This is not correct.
    >
    > When you reference a web service, a proxy class for the web service is
    > created on the web service consumer. BUT, proxies for all possible
    > webMethod return types are NOT created.
    >
    > If the client will be receiving a strongly-typed DataSet, then the client
    > will need this class referenced directly. This can be accomplished by the
    > strongly-typed DataSet existing in a separate assembly that both the web
    > service and it's consumer can both reference separately, or a copy of the
    > class exists in another place for the client to reference.
    >


    Sorry, I don't know where you get this from. Maybe you're talking about .NET
    1.1?

    Of course proxies are created for the WebMethod return types. How do you
    expect a client to be able to access them?

    I think you're confusing Web Services and Remoting. In the case of Remoting,
    you_do_ share the data types.

    John
     
    John Saunders, Mar 6, 2007
    #17
  18. "Scott M." <> wrote in message
    news:%...
    > No John, only the web service class gets a proxy created for it. Not the
    > return types of the web method calls.


    Sorry, man, you need to go check your facts. Create an example and see what
    happens. I did, and it behaves as I posted.

    My only question (which I'll check when I get a chance) is what happens when
    there's more than one typed dataset involved. One of the posters said that
    only one proxy is generated, and since my example only used one typed
    dataset, I can't tell if he's correct or not.

    John
     
    John Saunders, Mar 6, 2007
    #18
  19. "Scott M." <> wrote in message
    news:%...
    > XSD's can't be proxies as XSD's aren't classes. You are confusing Schemas
    > with typed dataSets.


    Scott, have you noticed any .xsd files associated with strongly-typed
    DataSets? Do you have strongly-typed datasets in your projects which do NOT
    have an .XSD file nearby?

    John
     
    John Saunders, Mar 6, 2007
    #19
  20. N. Shehzad

    Scott M. Guest

    They are related, but they are not one in the same. Have you noticed that
    you can delete either the typed dataset or the XSD and continue to use
    whichever remains?

    XSD's are not a MS invention, they are the W3C standard schema mechanism. A
    typed DataSet is a .NET class that is modeled after your data structure, an
    XSD is an XML Schema that is modeled after your data.

    They can work together, but they are not the same thing. An XSD is not
    defined in the .NET Framework. A DataSet is. An XSD is not a class (and so
    you can't have a proxy class for something that isn't a class in the first
    place), a typed DataSet is.

    "John Saunders" <john.saunders at trizetto.com> wrote in message
    news:...
    > "Scott M." <> wrote in message
    > news:%...
    >> XSD's can't be proxies as XSD's aren't classes. You are confusing
    >> Schemas with typed dataSets.

    >
    > Scott, have you noticed any .xsd files associated with strongly-typed
    > DataSets? Do you have strongly-typed datasets in your projects which do
    > NOT have an .XSD file nearby?
    >
    > John
    >
    >
     
    Scott M., Mar 6, 2007
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Narayanan Sankaranarayanan

    Custom Namespace For Strongly Typed DataSet

    Narayanan Sankaranarayanan, Dec 15, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,097
    Narayanan Sankaranarayanan
    Dec 15, 2004
  2. Imran

    Strongly Typed dataset

    Imran, Jan 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    578
    Richard A. Lowe
    Jan 23, 2004
  3. =?Utf-8?B?QW5kcmUgUmFuaWVyaQ==?=

    Help with creating strongly typed DataSet

    =?Utf-8?B?QW5kcmUgUmFuaWVyaQ==?=, Apr 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    526
    Rick Strahl [MVP]
    Apr 19, 2004
  4. HardBap
    Replies:
    1
    Views:
    1,937
    Gabriel Lozano-MorĂ¡n
    Jun 30, 2005
  5. Spotnick
    Replies:
    0
    Views:
    1,580
    Spotnick
    Jan 21, 2006
Loading...

Share This Page