Mega Code Archive

 
Categories / Delphi / .NET
 

Another Using the Borland WebService BabelCode

Title: Another Using the Borland WebService BabelCode Question: Many web service samples out there are written in .net languages or Java. But since Delphi 6, we can write Win32 applications, which consume web services Answer: Daniel "sakura" Wischnewski describes, how the Borland Webservice Babelcode can be used with Delphi.NET. But since Delphi 6 we can write applications, which consume Webservices. Let me tell, what you must do, to use Babelcode within a Delphi.Win32 application. At first we will create a new application. Like Daniel, I use two TRichEdit boxes, one for the C# source and another for the translated Delphi source. Instead of a simple Button, I use TMainMenu and TCoolBar/TToolBar. And I use the TActionManager for centralized handling of the event methods.Now let's see, how we can include web service client. At first we need aclient interface for the web service. OK, select File - New, then go to the WebService area and double-click on WSDL-Importer. Write "http://dotnet.borland.com/babelcode/converter.asmx?WSDL" in the Edit Field as WSDL source. After Click next, we see the Code-Preview. At Finish a new unit was created. I name this: CS2DConverter.pas. Add this unit in uses clause of the Implementation area of main unit. Then select the THTTPRIO component (from the WebServices Tab) and put it on the main form. Now we must define some properties. WSDLLocation: http://dotnet.borland.com/babelcode/converter.asmx?WSDLService: BabelCodePort: BabelCodeSoapFurthermore we need an object of type BabelCodeSoapimplementation uses CS2DConverter; var soapBabelCode: BabelCodeSoap; This object must be initialized at begin and reset at the end of our programprocedureTfBabelCodeMain.FormCreate(Sender: TObject); begin soapBabelCode := HTTPRIO1 as BabelCodeSoap; end;procedure TfBabelCodeMain.FormDestroy(Sender: TObject); begin soapBabelCode := nil; end; So, now we can consume the web service. In order to do this, we retrieve the Method CSharpToDelphi of our web service object soapBabelCodeprocedure TfBabelCodeMain.aCS2DelphiExecute(Sender: TObject); begin try sbBabelCode.Panels[0].Text := 'Sende C#-Code'; sbBabelCode.Refresh; reDelphi.Text := soapBabelCode.CSharpToDelphi(reCSharp.Text); sbBabelCode.Panels[0].Text := 'Delphi-Code empfangen'; except on E: Exception do sbBabelCode.Panels[0].Text := 'Fehler: ' + E.Message; end; end;Finished. Now we can start our application. Put some C# source code in the text box, click on the Run-Button and after a few seconds we see the translation into Delphi.You can download the hole project (ZIP file, 8 KByte).