WCF, Typed Datasets and DataContracts

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • matthew-andrews@ntlworld.com

    WCF, Typed Datasets and DataContracts

    Hi,

    I'm new to this WCF world, and have attempted to create a WCF service
    which takes a typed dataset as its data contract. I know this isn't
    always put forward for interopability, but I'm working in a pure .Net
    environment (.Net 3.0) and VS2005.

    However, how do I get the client to populate this data object to send
    into the WCF service? After I generate the proxy class using svcutil
    and do;

    TypedDataSet ds = new TypedDataSet();

    The 'ds' object isn't what I'd expect from a dataset! So how'd I get
    data into it?!??!

    Sorry if vague...

    Alternatively any good web sites on WCF and data contracts?

    Cheers
  • Marc Gravell

    #2
    Re: WCF, Typed Datasets and DataContracts

    If you are working in pure .NET, and have control of both ends (and
    are just uwing WCF as a comms layer, rather than an interopability
    layer), then a sensible option is assembly sharing; put your contracts
    (service and data) into a single assembly, and reference that assembly
    from both the service (often running in IIS) and the client (generally
    an exe). Now you don't need to use svcutil at all! You just configure
    the endpoint in the config file, and use it. Both ends have exactly
    the same interpretation of what the data is, and it "just works".

    This also means you can have sensible business logic in your entity at
    the client, rather than just the raw proxy.

    Marc

    Comment

    • Marc Gravell

      #3
      Re: WCF, Typed Datasets and DataContracts

      I forgot to say... to represent the service, you can subclass
      ClientBase<T(wh ich is what svcutil does); but using generics you
      only have to do it once (obviously you need to add some other ctors
      etc if you want to use non-default endpoints):


      public sealed class WcfClient<T: System.ServiceM odel.ClientBase <T>,
      IDisposable where T : class
      {
      void IDisposable.Dis pose() { Dispose(); } // re-implement dispose
      public void Dispose()
      {
      try
      {// faulted state is poorly implemented by MS, and blocks
      Close() and Dispose()!
      switch (State)
      {
      case CommunicationSt ate.Opened:
      case CommunicationSt ate.Opening:
      Close(); break;
      case CommunicationSt ate.Faulted:
      Abort(); break;
      }
      }
      catch { }
      }
      public T Service
      {
      get { return base.Channel; }
      }
      }
      [ServiceContract]
      interface IFoo
      {
      [OperationContra ct]
      void Bar();
      }
      static class Program {
      static void Main()
      {
      // use our WCF service
      using (WcfClient<IFoo client = new WcfClient<IFoo> ())
      {
      client.Service. Bar();
      }
      }
      }

      Comment

      • matthew-andrews@ntlworld.com

        #4
        Re: WCF, Typed Datasets and DataContracts

        On Apr 24, 10:02 am, Marc Gravell <marc.grav...@g mail.comwrote:
        I forgot to say... to represent the service, you can subclass
        ClientBase<T(wh ich is what svcutil does); but using generics you
        only have to do it once (obviously you need to add some other ctors
        etc if you want to use non-default endpoints):
        >
        public sealed class WcfClient<T: System.ServiceM odel.ClientBase <T>,
        IDisposable where T : class
        {
        void IDisposable.Dis pose() { Dispose(); } // re-implement dispose
        public void Dispose()
        {
        try
        {// faulted state is poorly implemented by MS, and blocks
        Close() and Dispose()!
        switch (State)
        {
        case CommunicationSt ate.Opened:
        case CommunicationSt ate.Opening:
        Close(); break;
        case CommunicationSt ate.Faulted:
        Abort(); break;
        }
        }
        catch { }
        }
        public T Service
        {
        get { return base.Channel; }
        }}
        >
        [ServiceContract]
        interface IFoo
        {
        [OperationContra ct]
        void Bar();}
        >
        static class Program {
        static void Main()
        {
        // use our WCF service
        using (WcfClient<IFoo client = new WcfClient<IFoo> ())
        {
        client.Service. Bar();
        }
        }
        >
        }
        Marc,

        Many thanks this is exactly what I was looking for, it works a
        treat.

        Cheers
        Mat

        Comment

        • sloan

          #5
          Re: WCF, Typed Datasets and DataContracts

          You can take a look here as well:

          http://sholliday.space s.live.com/Blog/cns!A68482B9628 A842A!158.entry

          WCF with Interface Development


          If you want to stick with strong datasets, that would work with the above
          setup as well.





          <matthew-andrews@ntlworl d.comwrote in message
          news:cd719bbd-0a85-4495-a64d-0bb2701f2957@34 g2000hsf.google groups.com...
          Hi,
          >
          I'm new to this WCF world, and have attempted to create a WCF service
          which takes a typed dataset as its data contract. I know this isn't
          always put forward for interopability, but I'm working in a pure .Net
          environment (.Net 3.0) and VS2005.
          >
          However, how do I get the client to populate this data object to send
          into the WCF service? After I generate the proxy class using svcutil
          and do;
          >
          TypedDataSet ds = new TypedDataSet();
          >
          The 'ds' object isn't what I'd expect from a dataset! So how'd I get
          data into it?!??!
          >
          Sorry if vague...
          >
          Alternatively any good web sites on WCF and data contracts?
          >
          Cheers

          Comment

          Working...