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

Source: Internet
Author: User

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.