C ++ Builder6.0 calls C #'s WebServcie

Source: Internet
Author: User

Li fuwei

Due to special needs, the client software is easy to use BCB6.0. The process calls a WebService written in C. Record the experiment process for your reference. To put it bluntly, go straight to the theme:

1. Reference WebService address

In the BCB6.0 environment, File-New-Other-WebService-WSDL Importer. Note the address here. In the. NET environment, for example, if we use C # To write a client to call WebService, we can directly reference the address. For example, the format is "http: // 111.111.111.111: 1234" (the compiler will help you complete the rest). Here, in the BCB environment, we need to manually write the complete address. For example, "http: // 111.111.111.111: 1234/AlexService. asmx? WSDL ". After "Next", we can find the AlexService. cpp and AlexService. h files and save them.

2. Add the THTTPRIO Control

The role of this control is

THTTPRIO uses HTTP messages to call remote interfaced objects using SOAP.

Use THTTPRIO to generate statically-linked callto invokable interfaces on a remote Web Service application.

There are several attribute settings.


Start with the following attribute


1. WSDLLocation. select from the drop-down menu.


2, Service, select from the drop-down menu


3. Select the Port from the drop-down menu. There are two options: ABCDWebServiceSoap and ABCDWebServiceSoap12. Select the first one. (Because BCB6.0 does not support WebServiceSoap12 well)


3. Add reference

1. Add a header file

In the form Form1.h File

Add the header file of AlexService. h.

2. Statement


Class TForm1: public TForm
{
_ Published: // IDE-managed Components
TEdit * Edit1;
TEdit * Edit2;
TLabel * Label1;
TLabel * Label2;
TButton * Button1;
THTTPRIO * HTTPRIO1;
Void _ fastcall Button1Click (TObject * Sender );
Private: // User declarations
Public: // User declarations
_ Fastcall TForm1 (TComponent * Owner );
_ Di_AlexServiceSoap FAlexService;
_ Di_AlexServiceSoap GetAlexServiceSoap ();
_ Property
_ Di_AlexServiceSoap AlexService = {read = GetAlexWebServiceSoap };
};

 

3. Reference

 

_ Fastcall TForm1: TForm1 (TComponent * Owner)
: TForm (Owner)
{
}
//---------------------------------------------------------------------------

_ Di_AlexServiceSoap TForm1: GetAlexServiceSoap ()
{
If (! FAlexService)
{
HTTPRIO1-> QueryInterface (FAlexService );
}
Return FAlexService;
}
//---------------------------------------------------------------------------

Void _ fastcall TForm1: Button1Click (TObject * Sender)
{
If (AlexService)
{
Logon * pLogon;
PLogon = (Logon *) AlexService-> Client_LogOn ("Li fuwei", "Alex ");
If (pLogon-> bolLogOn = True)
{
ShowMessage ("Logon successful ");
// PLogon-> strCompany =? Here is other content of the struct.
// PLogon-> iUid =?
}
Else
ShowMessage ("Logon Failed ");
}
}
//---------------------------------------------------------------------------
The above is an interface demonstration of user logon. It should be noted that the login result here is not a pure bool value, but a struct. Many people may encounter problems when calling the WebService of C # That contains struct functions in C ++. It is also demonstrated here.

3. parameter passing is supported.

The above is basically the completion of the BCB environment for the C # WebService call, but you may find that the server still cannot receive the passed function parameters. For example, AlexService-> Client_LogOn ("Li fuwei", "Alex"), two parameters cannot be passed into the server. Some people may wonder if something is wrong with communication? Permission? Firewall? Don't worry. This is a problem with character sets. In this example, we may find that only numbers are allowed, but Chinese and English parameters are not allowed. The reason is that the character set is inconsistent. As a result, the server receives garbled parameters instead of parameters. So we need to make three steps to adjust the character set.

1, in AlexService. cpp,

THTTPRIO * rio = new THTTPRIO (0); followed by the following two sentences:

 

//
Rio-> HTTPWebNode-> UseUTF8InHeader = true;
Rio-> Converter-> Options <soUTF8InHeader;
//
2, still in AlexService. cpp,

 

Static void RegTypes () {at the end of this function, we need to add the following paragraph}

 

InvRegistry ()-> RegisterInvokeOptions (_ interfaceTypeinfo (AlexServiceSoap), ioDocument );
3. Adjust the character set of the THTTPRIO control.

The properties of this control have two bool values about utf8. Please change them to true. (Utf8 is available for the attribute names)

 


So far, the Webservice of C # is called in BCB6.0.

If you have any suggestions or questions, please email me.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.