C Builder 6 BizSnap / SOAP / WebService (1)
- An example of Hello World!
As a brother of Delphi, C Builder is in a lot of aspects, which is of course similar in SOAP / WebService. Withd the development of SOAP / WebService application with Delphi, this site has been introduced, and the prawn Li Wei has already published a monograph, so I don't want to say more. But because of the previous few days, I saw someone in the forum in discussing Li Wei's book and using C Builder to do SOAP / WebService applications, I also wrote a few C in the articles of this station. Builder's article. Platforms used: Borland C Builder 6 Update1, Windows 2000 Server, IIS5 server: 1.New | WebServices | SOAP Server Application, as shown below, except for the icon in the upper left corner than Delphi 6 Update 2, except for icons in the upper left corner: Select the web app debugger executeable type, coclass name is: WadsoapDemo1, as shown below: After confirming, you will automatically prompt whether you want to create a new interface, you can open a new interface guide, if you want to add an interface, you can in New | WebServices Select SOAP Server Interface You can also open a new interface Wizard: 2. New Interface Wizard is as shown below, enter the interface name: Hello can generate a SOAP server interface: If you select Generate Sample Methods, you can generate a series of interfaces while generating the interface. Methods, compare how to define methods in interfaces, using this option, can easily learn the SOAP development method of C Builder 6. Service Activation Model can specify how to activate the server: Per Request (activation time time) / Global (globally). The default is Per Request, in this way, the service is established when the client's request is requested, and the service is also ended after the response; for the global mode, only one service instance is only one service instance, all client service requests are found Treatment, specifically by a global static function called XXXFactory; 3.SaveAll, Unit1 named: mainwm, project1 named: demo1, Hello does not change the name; 4. In the header file of the interface unit (Hello.h) Add a method - getHello, as follows: __interface interface_uuid ("{3C8C8426-1CF2-423D-B09E-5FEB5716B3C4}") Ihello: public invokable {public: Virtual Ansistring getHello (int AID) = 0; // Add method} ; Typedef DelphiInterface
_di_ihello; one of these __interface is not a new keyword (Borland does not dare to change C standard ^ _ ^), it is just a macro, in fact, it is Class, but more clearly explains this is An interface, the so-called interface is required to use the __interface defined class must be a fully abstract class (all member functions must be a pure virtual function); so our new way GetHello is a pure virtual function. 5. Implement the GetHello function, the following is the class definition that generated in the interface unit file (Hello.cpp) and the method we joys and its implementation: Class ThelloImpl: Public TinvokableClass, Public Ihello {public: Ansistring GetHello (int AID); / / this is the definition of the new method / * IUnknown * / HRESULT STDMETHODCALLTYPE QueryInterface (const GUID & IID, void ** Obj) {return GetInterface (IID, Obj) S_OK:? E_NOINTERFACE;} ULONG STDMETHODCALLTYPE AddRef () {return TInterfacedObject :: _AddRef ();} ULONG STDMETHODCALLTYPE Release () {return TInterfacedObject :: _ Release ();} / * Ensures that the class is not abstract * / void checkValid () {delete new THelloImpl ();}}; AnsiString THelloImpl :: getHello (int AID) {if (AID == 1) Return "Hello"; Else Return "World";} As of the comment description, IUNKNOWN interface is implemented in this class, and through a checkvalid () function Ensure that this class implements all pure virtual functions defined in the interface. The GetHello is our new interface method, including a very simple implementation. 6. The auto-generated code below is used for registration interfaces and its realization, because there is no Initialization like delphi in C , so it is to implement: Static void regtypes () {invregistry ( ) -> registerInterface (__ interfaceTypeinfo (IHello)); InvRegistry () -> RegisterInvokableClass (__ classid (THelloImpl));} # pragma startup RegTypes 32 7. the compiler can generate: Demo1.exe; first run once Demo1.exe, complete Start Web App Debugger after registration. Open the browser, enter the URL as: http: // localhost: 1024 / demo1.wadsoapdemo1 to see a standard SOAP application description page, click to enter the appropriate link to see the associated WSDL.