Recently, I found some examples of calling Web Services compiled by ASP. NET in Win32 environment.

Source: Internet
Author: User
Tags dotnet

1. delphi
nowadays, Web services are getting increasingly popular. In the Web Service developed by DOTNET, how does Delphi 7 conveniently call the Web Service written by DOTNET?
there are two methods: one is to convert the Web Service written by DOTNET into an interface unit file in the wsdlimp tool in Delphi 7, another method is to use Microsoft soap Toolkit (msst) tool provided by Ms.
The following describes how to use wsdlimp to call C # To write a simple Web Service:
Start.. Net tool. In the C # project, select ASP. net web service, written in Code

[Webmethod]
Public double add (double S1, double S2)
{
Return S1 + S2;
}
After the accessory is generated, enter http: // localhost/aspnetws/service1.asmx in IE.
You will see a link to add, click to enter, and call the test:
For example, if S1 is 34 and S2 is 235.34
<? XML version = "1.0" encoding = "UTF-8"?>
<Double xmlns = "http://tempuri.org/"> 269.34000000000003 </Double>
Enter http: // localhost/aspnetws/service1.asmx? WSDL. The WSDL unit is displayed.
After the test is successful, find the wsdlimp.exe tool in the bin directory of Delphi 7 and copy it to one place,
Enter wsdlimp http: // localhost/aspnetws/service1.asmx in the command prompt? WSDL
A service. Pas file is generated in the current directory, which is the interface file to be used in Delphi.

Start Delphi 7, create an application project, and add a tbutton component;
Add invokeregistry, Rio, soaphttpclient, and service1 to uses;

Procedure tform1.btn _ cshapwsclick (Sender: tobject );
VaR
Wsresult: Double;
Wsiserver: service1soap;
Begin
Wsiserver: = getservice1soap (true, '', httprio1 );
Wsresult: = wsiserver. Add (23,342.234 );

Showmessage ('wsresult: '+ floattostr (wsresult ));
End;
Obtain the add method written in C.
The above is written in vs. Net (C #) and Delphi 7!

1.1 sample

Use Delphi and WebServices technology to develop text message applicationsProgram

Abstract: This article describes in detail how to develop Web Services-based applications in Delphi by using Delphi and Web services.

Keywords: Delphi; web service; SMS Application Development

When talking about application development based on Web Services technology, the development tool that most people first think of is vs.net. In fact, as the leader of fast application development tools (RAD, delphi has supported the development and application of Web Services since 6.0, this document describes how to develop a Web Services-based application system in Delphi by using Delphi 7.0 to call the Web Service sent by Sina SMS.

Step 1: Prepare for the Sina text message web service. The Web service address sent by Sina is http://smsinter.sina.com.cn/ws/smswebservice0101.wsdl. the Web Service has only one method, namely string sendxml (carrier, userid, password, mobilenumber, content, msgtype ). All parameters are of the string type. Their meanings are as follows (which may be incorrect ).

Carrier: Carrier name. It seems that you can enter "Sina" at will. If you enter other values, the message sending speed is very slow;

Userid: your mobile phone ID registered on Sina wireless, if you have not registered your mobile phone on the http://sms.sina.com.cn, you can not use this web service to send text messages;

Password: the password you used when registering your mobile phone on Sina wireless;

Mobilenumber: the mobile phone number of the other party;

Content: The content of the short message;

Msgtype: the type of short message to be sent. I estimate that MMS is supported, but I don't know how to use it. It seems that I can enter anything at will. I use "text ".

For more information about the billing standard, see the description on the Sina wireless website. It may be a dime, but it may also be a two-way license. It is not clear. Because the background may use the message queue mechanism, there may be a long delay during busy hours.

Step 2: Create a blank application. Run Delphi 7 and open the [file]-> [new]-> [application] menu. Delphi automatically generates a default project. Change the default form form1 to SMS, and save the project as smsdemo. prj. As shown in:

Figure 1

Step 3: introduce web service ., Open the [file]-> [new]-> [other] menu, select the WebServices tab page in the pop-up window, and then select the WSDL importer option, click OK to bring up the WSDL importer wizard window, as shown in figure 2. Enter the http://smsinter.sina.com.cn/ws/smswebservice0101.wsdl in the location of WSDL file or URL on it (note, do not enter the error !), Click the next button, and then click finishi to complete the introduction of the SMS web service. In this case, a file named smswebservice0101.pas will be added to the project file. This is an automatic web service import declarative file generated by Delphi. Do not modify it manually.

Figure 2

Step 4: Call the SMS sending interface of web service. In the SMS form, four tedit controls, one tbutton control, one tmemo control, and five tlabel controls are added in sequence, which are arranged and set in figure 3.

Figure 3

The uses statement of the smsfrm unit contains smswebservice0101, so that the form can access the Web Service Interface sent by Sina.

Write the following code in The onclick event of the send button:

Procedure TSMS. button1click (Sender: tobject );

Begin

Memo1.text: = getsmswebservicesoapport. sendxml (edit1.text,

Edit2.text, edit3.text, edit4.text, edit5.text, ''text '');

End;

Note: edit1, edit2, edit3, edit4, and edit5 correspond to the operator, user name, password, peer number, and message content on the Interface respectively. Feedback on the Interface corresponding to memo1.

Step 5: use the Web Service short message sending interface to send short messages. Compile and run smsdemo. prj: enter your mobile phone ID and password registered on Sina wireless in the user name, enter your password on Sina wireless, and then enter the recipient's mobile phone number and message content, click the send button. After a moment, the Web Service feedback will be displayed in the feedback box. If everything is normal, the system will prompt you that the text message is sent successfully.

Summary

From the above example, we can see that as long as you understand the concept of Web Services, it is not very difficult to develop Web Services-based applications with the help of Delphi. Web services is most suitable for developing cross-platform and cross-network communications (because HTTP is allowed by the firewall) programs, which can span heterogeneous architectures, contacting customers, suppliers, business partners, and internal information systems is the best solution for integrating B2B e-commerce and enterprise information. Every company needs to expose the business logic and become a web service, so that any designated partner can call the business logic, regardless of the platform on which their system runs, development tools used. Web services is a very popular and rapidly developing technology. This article is just a little bit of learning experience by the author. You are welcome to correct it. (Full text)

Note: I am grateful for the Sina messaging Web Service technology in http://blog.joycode.com/joy/posts/16939.aspx.

Showwindow.
Unit
System

VaR cmdshow: integer;
Description
In the program, when the application creates the main window, the cmdshow variable contains the parameter values that Windows wants to pass to showwindow.
In the library (DLL), cmdshow is always 0.

3. compilerversion constant
Indicates the version number of the Delphi compiler.
Unit
System

Const compilerversion = 15.0;
Description
You can use compilerversion to test the configuration level of the Delphi compiler. If you want to conditional update the special code using the Delphi language, this will be very useful (this is useful if you want to conditionalize code that takes advantage of newer features in the Delphi language ).

4. exitprocessproc variable
Exitprocessproc specifies the process (Procedure) That is last executed before the application is shut down (shut down ).
Unit
System

VaR exitprocessproc: procedure;
Description
Assign the value to exitprocessproc to specify the process you want to execute before the application is closed. The value of exitprocessproc is a process without parameters.

5. getfileversion Function
Returns the file version.
Unit
Sysutils

Function getfileversion (const afilename: string): Cardinal;
Description
Getfileversion returns the most meaningful 32-bit binary version of a file. Afilename specifies the file name, which can be searched using the same path as the loadlibrary function.

6. getmodulename Function
Returns the fully qualified name (fully qualified name) of the module for the given handle ).
Unit
Sysutils

Function getmodulename (module: hmodule): string;
Description
Call getmodulefilename to obtain the fully qualified name of the module with the given handle.
Module is the module handle.

7. hinstance variable
Handle, which is provided to the module by windows ).
Unit
Sysinit

VaR hinstance: longword;
Description
Hinstance contains the instance handle of applications or libraries provided by Windows

8. hintwindowclass variable
Class used to display the help hint window.
Unit
Forms

VaR hintwindowclass: thintwindowclass = thintwindow;
Description
When the application displays the help hint, it creates an hintwindowclass instance to depict the window for displaying the prompt. The application creates a thintwindow derived class and then assigns the derived class to the hintwindowclass variable when the application starts. This window can be customized.

9. initproc variable
Initproc is the last installation initialization process.
Unit
System

VaR initproc: pointer;
Description
Assign a value to initproc to specify the process you want to execute when the application starts. Initproc is a non-parameter process. For example:
Procedure myinitprocedure;
...
Initialization
Initproc: = @ myinitprocedure;
Begin
End;
Only one initialization process can be assigned an initproc variable. If your application defines multiple initialization processes, only the last one that is assigned to initproc will be executed. To allow execution of other initialization processes, you must "Link" the process and call the original value from the new value of initproc. For example, the following code from the comobj unit saves the original value of initproc before the new value is assigned, and then calls and saves the value in the new initialization process:
Saveinitproc: = initproc;
Initproc: = @ initcomobj;

10. isconsole variable
Indicates whether the module is compiled as a console application.
Unit
System

VaR isconsole: Boolean;
Description
If the module is compiled as a console application, the isconsole variable is true. This will be true in both the executable file and DLL ).

11. islibrary Variables
Indicates whether the module is a DLL.
Unit
System

VaR islibrary: Boolean;
Description
If the module is a DLL, The islibrary variable is true.

12. jitenable variable
Controls when the scheduler is called in time (controls when the just-in-time debugger is called ).
Unit
System

VaR jitenable: byte = 0;
Description
Use jitenable to indicate which types of exceptions will trigger the timely debugger.
When jitenable is 0 (default), all exceptions are handled by the Exception Handling Mechanism of the application. The timely debugger is called only when the application does not provide any mechanism to capture exceptions. Note: Except for the initialization and termination areas in the Delphi unit, any application that contains the forms Unit provides Exception Handling (through the Application object ), does not trigger the timely debugger (note that any application that has des the forms Unit provides Exception Handling (via the application object) for all but the initialization and finalization sections and does not trigger the just-in-time debugger ).
When jitenable is 1, any non-native exceptions (exceptions caused by Code Compiled using other products ). Will trigger the timely debugger. Native exceptions are handled by the Exception Handling Mechanism of the application.
When jitenable is greater than 1, all exceptions will trigger the timely debugger.
Note: When you install IDE, it will be registered as a timely debugger. If you have installed other tools with debuggers, they may have registered themselves and covered ide registration.

13. Ages Functions
List the locale for which support is available ).
Unit
Sysutils

Function languages ages: tlanguages;
Description
You can use the value returned by ages to obtain region information supported by the system. This function is only available on Windows.

14. maininstance variable
Instance handle that indicates the main executable files.
Unit
System

VaR maininstance: longword;
Description
Use maininstance to obtain the instance handle of the main executable files in an application. In applications that use runtime libraries or packages, this is useful when you need executable files instead of library handles.
Note: Do not use maininstance when running a clx dynamic link library (Windows) or shared object (Linux) from an executable file compiled with other tools.

15. mainthreadid variable
Indicates the main execution thread in the current module.
Unit
System

VaR mainthreadid: longword;
Description
Use mainthreadid to obtain the thread ID of the main execution thread (the current thread at module initialization.
During debugging, the main thread ID is displayed in the thread status box.
In Windows, the value of mainthreadid is compatible with the thread ID required for some WIN32API calls.

16. noerrmsg variable
Determines whether the application displays an error message when a running error occurs.
Unit
System

VaR noerrmsg: Boolean = false;
Description
In Windows, set noerrmsg to control whether a message is displayed to indicate that a runtime error has occurred. When noerrmsg is false (default value), a runtime error will cause the application to display a message box to indicate the type of the error. When noerrmsg is true, these messages are forbidden.
In Linux, noerrmsg has no effect.
Note: The sysutils unit converts most runtime errors into exceptions. If your application contains sysutils, even if noerrmsg is false, the runtime error message box may not be displayed.

17. popuplist variable
Provides centralized processing for Windows messages in the pop-up menu (popup menu ).
Unit
Menus
VaR popuplist: tpopuplist;
Description
You can use popuplist to access all the pop-up menus in the application or the window handle for accessing the response pop-up menu message. Popuplist maintains the list of all pop-up menu components created in the application. This list stores a handle for a hidden window that centrally processes Windows messages sent to these pop-up menus.

18. rtlversion constant
Indicates the version number of the Delphi runtime database.
Unit
System

Const rtlversion = 15.0;
Description
You can use rtlversion to check the version number of the Delphi Runtime library that is not dependent on the compiler version.

19. Screen variable
Display a screen device
Unit
Forms

VaR screen: tscreen;
Description
The screen variable is a tscreen component that represents the screen of the system in which the application is running. By default, an application creates a screen component based on information about the current screen device and assigns it to the screen variable.

20. win32platform variable
The identifier of the Win32 platform.
Unit
Sysutils

VaR win32platform: integer = 0;
Description
Win32platform is used to identify the type of Win32 platform in which the system runs. This will be one of the following values:
Value Meaning
Ver_platform_win32s system is Win32
Ver_platform_win32_windows is Windows 95
Ver_platform_wn32_nt is Windows NT
Win32platform is only available on Windows.

HTML webpage callMethod

<Form target = "_ blank" Action = 'HTTP: // www.ydcom.net/service/s_comm.asmx/getczid' method = "Post"> "〉
<Table cellspacing = "0" cellpadding = "4" frame = "box" bordercolor = "# dcdcdc" rules = "NONE" style = "border-collapse: collapse;"> ;"〉
<Tr> 〉
<TD class = "frmheader" background = "# dcdcdc" style = "border-Right: 2px solid white;"> parameter </TD> 〉
<TD class = "frmheader" background = "# dcdcdc"> value </TD> 〉
</Tr> 〉
<Tr> 〉
<TD class = "frmtext" style = "color: #000000; font-weight: normal;"> stypenum: </TD> 〉
<TD> <input class = "frminput" type = "text" size = "50" name = "stypenum"> </TD> 〉
</Tr> 〉
<Tr> 〉
<TD> </TD> 〉
<TD align = "right"> <input type = "Submit" value = "call" class = "button"> </TD> 〉
</Tr> 〉
</Table> 〉
</Form> 〉

Example: how to call a service to generate 18-bit key values

Related documents:Use Vbscript to call Web Services

ASP call method (soap method)

Dim URL, XMLHTTP, Dom, node, xmldoc
'Construct different SOAP requests based on different methods on the WebService test page.
Soaprequest =" "&_
" "Xmlns: XSD =" & CHR (34) & "http://www.w3.org/2001/XMLSchema" & CHR (34 )&""&_
"Xmlns: Soap =" & CHR (34) & "http://schemas.xmlsoap.org/soap/envelope/" & CHR (34) & "> "&_
""&_
" "&_
" 311 "&_
" "&_
""&_
""
Url = "http://www.ydcom.net/service/S_COMM.asmx? Methodname = getczid"
Set xmldoc = server. Createobject ("MSXML. domdocument ")
Xmldoc. loadxml (soaprequest)
Set XMLHTTP = server. Createobject ("msxml2.xmlhttp ")
XMLHTTP. Open "Post", URL, false
XMLHTTP. setRequestHeader "Content-Type", "text/XML; charset = UTF-8"
XMLHTTP. setRequestHeader "soapaction", "http://www.ydcom.net/service/SrvCOMM/S_COMM/GetCZID"
XMLHTTP. setRequestHeader "Content-Length", Len (soaprequest)
XMLHTTP. Send (xmldoc)

If xml http. Status = 200 then
Xmldoc. Load (XMLHTTP. responsexml)
Response. Write XMLHTTP. Status &"
"
Response. Write XMLHTTP. statustext &"
The execution result is :"
Response. Write xmldoc. getelementsbytagname ("getczidresult") (0). Text
Else
Response. Write XMLHTTP. Status &"
"
Response. Write XMLHTTP. statustext
End if
%>

Example: how to use ASP to call the service to generate 18-bit key value ASP source file code

Note: In general, the list page of WebService is used to construct different soaprequests. Then,
Retrieve the returned value xmldoc. getelementsbytagname from the returned xmldoc

ASP call method (HTTP)

Set objhttp = server. Createobject ("msxml2.xmlhttp ")
Set xmldoc = server. Createobject ("MSXML. domdocument ")
Strwebserviceurl = "http://www.ydcom.net/service/S_COMM.asmx/GetCZID"
'Set parameters and their values
Strrequest = "stypenum = 311"
Objhttp. Open "Post", strwebserviceurl, false
'Setting this Content-Type is very important.
Objhttp. setRequestHeader "Content-Type", "application/X-WWW-form-urlencoded"
Objhttp. setRequestHeader ("Content-Length: 30 ")
Objhttp. Send (strrequest)
Bok = xmldoc. Load (objhttp. responsexml)
'Look at the status value
If objhttp. Status = 200 then
Xmlstr = xmldoc. xml
Response. Write xmlstr
Else
Response. Write objhttp. statu &"
"
Response. Write objhttp. statustext
End if
%>

Example: how to use ASP to call the service to generate 18-bit key value ASP source file code

Call methods in VB6

Dim strxml as string
Dim STR as string
STR = text2.text
'Define a SOAP message
Strxml =" Xmlns: xsi = 'HTTP: // www.w3.org/2001/xmlschema-instance'
Xmlns: XSD = 'HTTP: // www.w3.org/2001/xmlschema'
Xmlns: Soap = 'HTTP: // schemas.xmlsoap.org/soap/envelope/'> "& STR &
" "
'Define an HTTP object and send a post message to the server.
Dim h as msxml2.serverxmlhttp40
'Define an XML Document Object and convert the handwritten or accepted XML content into an XML Object
Dim X as msxml2.domdocument40
'Initialize the XML Object
Set x = new msxml2.domdocument40
'Convert a handwritten soap string to an XML Object
X. loadxml strxml
'Initialize the HTTP object
Set H = new msxml2.serverxmlhttp40
'Send post message to the specified URL
H. Open "Post", "http: // localhost/testwebservice/service1.asmx", false
H. setRequestHeader "Content-Type", "text/XML"
H. Send (strxml)
While H. readystate <> 4
Wend
'Display returned XML Information
Text1.text = H. responsetext
'Parse the returned XML Information and display the returned value.
Set x = new msxml2.domdocument40
X. loadxml text1.text
Text1.text = x. childnodes (1). Text

Call methods in VB. NET

1, first add web reference, address: http://www.ydcom.net/service/s_comm.asmx

2. Definition: dim scom as new net. ydcom. www. s_comm

3. Call: dim strczid as string = scomm. getczid ("313 ")

Example: how to use VB. NET to call the service to generate 18-bit key value VB. NET source file code

Call methods in Pb. Net (pb9)

Soapconnection Conn
Test_wsservice1soap scom
Long rval
// String str_endpoint
// Str_endpoint = "http://www.ydcom.net/service/s_comm.asmx? WSDL"
Conn = create soapconnection
Rval = conn. createinstance (scom, "test_wsservice1soap ")
Sle_1.text = scom. getczid ("313 "))
Destroy Conn

Related Article

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.