Starting WCF Programming in Delphi 2007

by john 11/7/2007 8:42:00 AM

I have just started looking into Windows Communication Foundation.

Pawel Glowacki created a really nice article on the CodeGear Developer Network titled Introduction to WCF Programming in Delphi.

I'm particularly interested in web development and I noticed that there is a WCF Service Template in Visual Studio 2005, so I have converted it to Delphi.

I have uploaded the template to CodeCentral.

If you are not sure how to use the template, I have a blog post about templates and how you install them,

Once installed you can now create a new WCF Service application

 

You should end up with a new ASP.Net  Web Application with a single WCF Service.

 

Assuming that you have already installed Microsoft dotnet v3.0, you can now build and run the application.

The service description should now appear in a browser.

 

To exercise the web application you need to do the following:-

1) Create a new VCL.Net application

2) Add a reference to the System.ServiceModel assembly

3) Add

C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0

to the compiler search path

4) Your code might look something like

uses
  System.ServiceModel, Service, System.ServiceModel.Channels;

{$R *.nfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  aEndpointAddress: EndpointAddress;
  aBinding: WSHttpBinding;
  aFactory: ChannelFactory<IMyService>;
  aChannel: IMyService;
  someValue: string;
  value: DataContract1;
begin

  try
    aEndpointAddress := EndpointAddress.Create('http://localhost:8080/WCFServiceWebApplication1/Service.svc');
    aBinding := WSHttpBinding.Create;
    aFactory := ChannelFactory<IMyService>.Create(aBinding, aEndpointAddress);
    aChannel := aFactory.CreateChannel;
    try
      someValue:=aChannel.MyOperation1('John');
      ShowMessage(someValue);

      value:= DataContract1.Create;

      value.FirstName:='John';
      value.LastName:='Moshakis';

      aChannel.MyOperation2(value);
      ShowMessage(someValue);

    finally
      IChannel(aChannel).Close;
      IDisposable(aChannel).Dispose;
    end;
  except
    on E:Exception do
    begin
      raise;
    end;

  end;

end;
 

 A word of warning, if like me you use Cassini as your web server, I think you need to upgrade to the latest version. Below is a screenshot of the application running with the version of Cassini supplied with Delphi 2007.

 

 

Please read my blog post about upgrading Cassini.

Comments welcome 

 I also see that Pawel is doing a presentation at CodeRage II titled "Delphi for .NET WCF Programming: Deeper Dive", I'm looking forward to listening to that,

Currently rated 3.0 by 2 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.Net 2.0 | WCF | Delphi | VCL.Net

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen

About the author

Name of author John Moshakis
I'm a software developer living in Toronto..

E-mail me Send mail

Calendar

<<  September 2017  >>
MoTuWeThFrSaSu
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

View posts in large calendar

Pages

    Recent posts

    Recent comments

    Authors

    Tags

    Don't show

      Disclaimer

      The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

      © Copyright 2017

      Sign in