Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WCF, Typed Datasets and DataContracts

346 views
Skip to first unread message

matthew...@ntlworld.com

unread,
Apr 24, 2008, 3:04:34 AM4/24/08
to
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

unread,
Apr 24, 2008, 4:52:40 AM4/24/08
to
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

Marc Gravell

unread,
Apr 24, 2008, 5:02:19 AM4/24/08
to
I forgot to say... to represent the service, you can subclass
ClientBase<T> (which 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.ServiceModel.ClientBase<T>,
IDisposable where T : class
{
void IDisposable.Dispose() { Dispose(); } // re-implement dispose
public void Dispose()
{
try
{// faulted state is poorly implemented by MS, and blocks
Close() and Dispose()!
switch (State)
{
case CommunicationState.Opened:
case CommunicationState.Opening:
Close(); break;
case CommunicationState.Faulted:
Abort(); break;
}
}
catch { }
}
public T Service
{
get { return base.Channel; }
}
}
[ServiceContract]
interface IFoo
{
[OperationContract]
void Bar();
}
static class Program {
static void Main()
{
// use our WCF service
using (WcfClient<IFoo> client = new WcfClient<IFoo>())
{
client.Service.Bar();
}
}
}

matthew...@ntlworld.com

unread,
Apr 24, 2008, 5:10:48 PM4/24/08
to

Marc,

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

Cheers
Mat

sloan

unread,
Apr 26, 2008, 1:33:49 PM4/26/08
to
You can take a look here as well:

http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!158.entry

WCF with Interface Development


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

<matthew...@ntlworld.com> wrote in message
news:cd719bbd-0a85-4495...@34g2000hsf.googlegroups.com...

0 new messages