線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2782
推到 Plurk!
推到 Facebook!

Simple Delphi Prism WCF service and Delphi 2009 client

 
pcplayer99
尊榮會員


發表:146
回覆:790
積分:632
註冊:2003-01-21

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-06-27 15:34:03 IP:121.15.xxx.xxx 訂閱
原文:http://blogs.embarcadero.com/pawelglowacki/2009/05/27/38726


It has been just few days since Delphi Prism May 2009 has been released. One of the most visible new things is its support for AOP through Cirrus framework. Jim McKeeth demonstrated Delphi Prism AOP demo during the recent DelphiLive!
conference and it was enlightning experience to see how aspects are
modifying code during the compilation time. The AOP is very interesting.

Yesterday I have been presenting ".NET Programming with Delphi
Prism" webinar. Of course AOP was the first demo, but I also thought
that it would be cool to adapt my old Delphi for .NET WCF demos to Delphi Prism. It did not take me long to have a simple Delphi Prism WCF "Simple Calculator" demo application up and running.

The WCF
architecture is a natural evolution of the first-generation web
services. It decouples XML messaging from the underlying communication
protocol and offers additional message exchange patterns. It is
possible to build WCF services in such a way that they can be accessed
by traditional Web Services clients, including Delphi 2009 VCL Forms
applications. WCF services can be hosted (for example in IIS) or
self-hosted (for example in a Console application).

For demo purposes I have decided to host my WCF service in Delphi
Prism Console application. Instead of starting from "WCF" template, I
have started from an empty Delphi Prism console project. The first
thing to do is to add to project references "System.ServiceModel"
assembly where most of the WCF types are defined.



In the second step I have added to my project two units for service
interface definition ("SimpleCalcIntf.pas") and for the actual service
implementation class ("SimpleCalcImpl.pas").



Note that the interface is decorated with "[ServiceContract]" and
methods with "[OperationContract]" attributes defined in the
"System.ServiceModel" namespace.



The WCF service implementaion class is trivial. Note that it is
enough to decorate interface with WCF attributes. The implementation
class does not need them.

That’s our WCF service. In the WCF architecture a service can be
access only through WCF endpoints. You can define endpoints either
declaratively with configuration file or in code. For demo purposes I’m
going to use the second approach. The last part of the WCF application
is hosting code that I’m going to place directly inside the program’s
"main" method.



If you now run this program you should see the following screen.



Now it you type into the browser the service URL, it should
display a test page with the URL for the WSDL file that you need as a
staring point for building web service client to it.



In order to import a web service into Delphi 2009 you need to use
"WSDL Importer" from the "New Items" dialog and specify the URL of the
WSDL file that descibes the service. In our case it is http://localhost:8080/DelphiPrism/?wsdl. The detailed steps for building a client application can be found here.

The source code for this demo project can be downloaded from CodeCentral.
系統時間:2024-04-19 12:04:19
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!