For starters, here's my development environment:
WinXP SP2, Visual Studio 2005 Team Edition for Software Developers, IIS,
WinFX Runtime 3.0 Beta 2 (Feb CTP), Windows SDK for WinFX Feb CTP,
Visual Studio 2005 Extensions for WinFX Feb CTP
The approach I'm using is to create two Visual Studio solutions: one for
services and one for
clients. This will make it easier to debug both server and client
simultaneously.
SERVICE SOLUTION
Create a new web site service app and a solution to hold it:
File > New > Web Site...
select WinFX Service
Enter location and language, hit OK
A project is created with Service.svc, Service.cs, and Web.config with
service name = MyService and endpoint contract = IMyService
Open IIS management console and right-click on your new service's web site,
then click
Properties. On the Directory tab, make sure it has an Application name
entered. If not,
you might be able to click on the Remove button, followed by clicking on the
create
button (the same physical button) to have an Application Name assigned.Next,
go to the Documents tab and add "Service.svc" to
the list of default documents for this website. Click OK.
At this point, you should be able to view your service in a browser. For
instance,
enter a URL something like:
http://localhost/<website_name>/Service.svc
or
http://localhost/<website_name>/Service.svc?wsdl
Or from IIS, right-click on the website name and select Browse.
A page should appear with the name of your service (e.g., MyService Service)
and some
sample code on how to use a proxy to access it.
NOTE that this step of "hitting" your service from a browser has the
side-effect of
loading the service's debug symbols, which will make it possible to debug
the service
from Visual Studio.
Close the solution.
WINDOWS APP CLIENT SOLUTION
Create a new Windows App and solution to hold it:
File > New > Project...
Select Visual C# or Visual Basic > Windows > Windows Application
Enter Name and location, hit OK
A project is created with Form1.cs and Program.cs.
Add a reference to System.ServiceModel:
Right-click on the client project in Solution Explorer and click on Add
Reference...
On the .NET tab, select System.ServiceModel, click OK
Add a Service Reference:
Right-click on the client project in Solution Explorer and click on Add
Service Reference...
In the URL box, enter the URL of your service. E.g.,
http://localhost/<service_website_name>/Service.svc
In the Service Reference name box, enter an arbitrary name to identify
the service.
(This name will be used to name the auto-generated .map and proxy code
file as well as
the namespace used in the proxy code file.)
The final steps show an example of using one of the service's operations to
populate a textbox
in the client app:
Open Form1 in the designer and add a textbox control.
View the code for Form1 and add some code to the Form1 constructor (after
InitializeComponent()) to populate the textbox. For example:
using (WindowsApplication1.svc.MyServiceProxy proxy = new
WindowsApplication1.svc.MyServiceProxy())
{
// Use the 'proxy' variable to call methods on the service.
textBox1.Text = proxy.MyOperation1("WCF");
}
(Note that my client project name is WindowsApplication1, the service
reference name I used
when adding the service reference was svc, and I used the auto-generated
service operation
named MyOperation1.)
Now you should be able to run your client application and see the textbox
filled with "Hello: WCF".
Of course that would be too easy for it to work the first time (you might be
luckier than me).
When I run the client at this point, I get an unhandled ProtocolException
pop-up with a 504 Proxy Timeout.
And so I have to edit my client's service.map file. When the Add Service
Reference step creates this file
from the
http://localhost URL that I gave it, it resolves the localhost name
to be the fully-qualified
network name for my computer. This name doesn't fly for whatever name
resolution-related reason that's
giving it gas. So I have to change the URL in the "<Endpoint Address=" back
to the original
"http://localhost" form. I have to do the same in the client's app.config
file for the
"<client><endpoint address=" value.
At this point, hopefully, it should run for you.
Beware also that when you modify your service and do the "Update Service
Reference" command from the
right-click menu of the client's .map file, these endpoint addresses will be
set back to the fully-qualified
computer name and you'll have to repair them yet again.
WEB APP CLIENT
So far I haven't been able to create a web app that can make use of the
service. Perhaps
someone out there can help. For starters, the right-click menu for an
ASP.NET website project
does not have an "Add Service Reference" command. Trying the "Add Web
Reference" command, instead,
fails. Also, trying to add the System.ServiceModel reference has no effect.