Beginner with Questions re: WPF, WCF, LINQ

D

Dave

Hi All,

I am coming from a PHP, Java background. I am just getting started with C#
and I am trying to figure out how to program something (I have about 3 months
to do it). All I want is a confirmation of the direction I am going and then
I will start to learn everything.

We have a DB2 database. I am assuming I can write a WCF service to access
this database and return the data from the service to a WPF front end app
(the service and front end will be on different machines). Will the data from
the service be returned in only XML format or can the service send the data
back in another format? If it sends back only in XML then can I use LINQ to
XML to display the data in a WPF front end? I guess I just need some kind of
confirmation that I am on the right track on how all these things work
together.

Thanks
 
A

Arne Vajhøj

Dave said:
We have a DB2 database. I am assuming I can write a WCF service to access
this database and return the data from the service to a WPF front end app
(the service and front end will be on different machines).

Yes. Note though that a SOA web service is supposed to expose
business services not raw table data.
Will the data from
the service be returned in only XML format or can the service send the data
back in another format?

WCF support multiple formats including SOAP and Remoting (equivalent
to Java RMI).
If it sends back only in XML then can I use LINQ to
XML to display the data in a WPF front end?

In theory yes, but that would be a cumbersome way to do it.

Let .NET unpack it so you have the same data structure as the server
send.

Arne
 
D

Dave

Thanks for the reply.

I was thinking the webserver would do something like:

User sends "Account Number" to service
Service replies with "Account Information, Balance, etc etc".
Then the front end would display the returned information somehow.

When you say "Let .NET unpack it" to get the same "data structure", are you
saying the Service can return data in a dat structure instead of just XML
data? If so, what is the technical term for this so I can start investigating
this way?

Thanks again
 
A

Arne Vajhøj

Dave said:
I was thinking the webserver would do something like:

User sends "Account Number" to service
Service replies with "Account Information, Balance, etc etc".
Then the front end would display the returned information somehow.

When you say "Let .NET unpack it" to get the same "data structure", are you
saying the Service can return data in a dat structure instead of just XML
data? If so, what is the technical term for this so I can start investigating
this way?

yes

web reference
web service stub

Let me give an example.

Oldfashioned .asmx not WCF, but anyway.

Server side:

public class Test : WebService
{
[WebMethod]
public Foobar TestIt()
{
Foobar res = new Foobar();
res.Iv = 123;
res.Sv = "ABC";
return res;
}
}

Client side:

Test serv = new Test();
Foobar tst = serv.TestIt();

The Test and Foobar class used client side are generated
from the WSDL of the web service.

Remoting works similar.

And WCF as well (from what I have read - I have not used WCF yet).

Arne
 
D

Dave

OK I think I understand. I guess my confusion was that I thought the service
only returned XML data. Returning data this way is much better.

Thanks

Arne Vajhøj said:
Dave said:
I was thinking the webserver would do something like:

User sends "Account Number" to service
Service replies with "Account Information, Balance, etc etc".
Then the front end would display the returned information somehow.

When you say "Let .NET unpack it" to get the same "data structure", are you
saying the Service can return data in a dat structure instead of just XML
data? If so, what is the technical term for this so I can start investigating
this way?

yes

web reference
web service stub

Let me give an example.

Oldfashioned .asmx not WCF, but anyway.

Server side:

public class Test : WebService
{
[WebMethod]
public Foobar TestIt()
{
Foobar res = new Foobar();
res.Iv = 123;
res.Sv = "ABC";
return res;
}
}

Client side:

Test serv = new Test();
Foobar tst = serv.TestIt();

The Test and Foobar class used client side are generated
from the WSDL of the web service.

Remoting works similar.

And WCF as well (from what I have read - I have not used WCF yet).

Arne
 
A

Arne Vajhøj

Dave said:
OK I think I understand. I guess my confusion was that I thought the service
only returned XML data. Returning data this way is much better.

It does. But you don't see it.

You write server side code that return an object. The container
serialize that object as SOAP XML.

You write client side code that calls a generated stub. That
stub deserialize the received SOAP XML as an object.

The benefits of the SOAP XML is that the client side
and server side does not need to be in the same technology. You
can call a Java web service from C# or a VB.NET web service in PHP.

But you do not need to worry about the details of SOAP XML. You can
focus on the real problem.

Arne
 
D

Dave

OK I am starting to understand. Basically the service does return XML but the
frontend will create a data object from the XML automagically.

Now I need to find a good tutorial on all this stuff.

Thanks again for clearing this up for me.
 
A

Arne Vajhøj

Dave said:
OK I am starting to understand. Basically the service does return XML but the
frontend will create a data object from the XML automagically.

Now I need to find a good tutorial on all this stuff.

Some random googling:

..asmx

http://my.execpc.com/~gopalan/dotnet/webservices/webservice_server.html
http://www.15seconds.com/issue/010430.htm

WCF

http://www.dotnetfun.com/articles/framework/3.0/WCFBasicServiceContract.aspx

remoting

http://www.csharphelp.com/archives2/archive314.html
http://www.beansoftware.com/NET-Tutorials/NET-Remoting-Tutorial.aspx

Arne
 
S

Steve Gerrard

Dave said:
OK I am starting to understand. Basically the service does return XML
but the frontend will create a data object from the XML automagically.

Now I need to find a good tutorial on all this stuff.

Thanks again for clearing this up for me.

Just to reiterate, a web service can return a DataSet. It will actually be XML
data, following Microsoft's diffgram XML schema, but for all intents and
purposes, it is a dataset.

The client can call the method that returns a dataset, perhaps passing some
parameter values, and assign the return value to a dataset variable. As you put
it, all the xml processing happens automagically.

It can be a bit bulky for returning many rows, since the column names will be
repeated twice for each row in the actual XML, but it works very smoothly.
 
A

Arne Vajhøj

Steve said:
Just to reiterate, a web service can return a DataSet. It will actually be XML
data, following Microsoft's diffgram XML schema, but for all intents and
purposes, it is a dataset.

The client can call the method that returns a dataset, perhaps passing some
parameter values, and assign the return value to a dataset variable. As you put
it, all the xml processing happens automagically.

It can be a bit bulky for returning many rows, since the column names will be
repeated twice for each row in the actual XML, but it works very smoothly.

I would not use a DataSet for a web service. It will not be consumable
from non-.NET clients.

Arne
 
S

Steve Gerrard

Arne said:
I would not use a DataSet for a web service. It will not be consumable
from non-.NET clients.

In the practical sense, it is quite unlikely. It is a published schema, so
technically it is possible for a non .Net program to receive the xml data and
the schema, and to create its own version of a dataset.

If you are developing both the web service and the client in .Net, however, and
that it is its principle purpose, it works out fine.
 
D

Dave

Thanks again for all the info....

For the immediate future, the client will be .NET but down the road (maybe
in a year or so) they will want me to do some Blackberry programming using
the same services. I was hoping I wouldn't need to rewrite anything....
 
S

Steve Gerrard

Dave said:
Thanks again for all the info....

For the immediate future, the client will be .NET but down the road
(maybe in a year or so) they will want me to do some Blackberry
programming using the same services. I was hoping I wouldn't need to
rewrite anything....

I have no idea what you would need for Blackberry.

One thing to consider is that if the web service is going to get the data from
the database as a dataset, you can then expose it two (or more) ways: one method
returns it as a dataset; another method returns it as an array of data elements,
or whatever.

I did a little thing like that to allow an older , non .Net, program to exchange
data with the service as arrays of strings. Not ready for public consumption,
but effective for the task at hand.

So you could build around a dataset now, and work out a second way to expose the
data later. Or you start creating all your own data classes that you would need
to make a more general purpose web service.
 
D

Dave

Thanks Steve,

I assume a dataset would be easier to work with than an array? I guess I
should go that route for now until I get up to speed on C#. I have alot to do
in a very short amount of time and I have never done any .NET programming so
right now Im looking for quickest and easiest.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top