The Web Service service written on C # is in the issue of Delphi down.

xiaoxiao2021-03-05  27

The Web Service service written on C # is in the issue of Delphi down.

The Web Service service written on C # is in the issue of Delphi down.

First of all, I think it is necessary to make a more comprehensive explanation of the .NET platform to develop WebService, the initial generation of Web Service is in the environment of e-commerce, and some problems are not easy to solve through traditional means, such as in applications. There is no business communication, data exchange, use DCOM, CORBA and other binary mechanisms have not passed, and they don't say they are limited by their own platforms, such as DCOM (Distribute Common Objects Model) can only do under Windows platform, and CORBA (Common Objects Request Broker Architecture is just the product under the Java platform. They want to implement data communication between applications is more difficult.

In this context, Web Services came into being, it solved a cross-language, cross-platform, and well-safe penetrating enterprise firewall. Its architecture is generally divided into five levels:

HTTP data expressed in the form SOAP (Simple Objects Access Protocol) data encapsulation WSDL (WebServices Description Language) description language format UDDI under (HyperText Transfer Protocol) channel for data communication XML (Extensable Markup Language) (Universal Description and Discovery Integration) unified Description, discovery and integration As its advantage, cross-language, cross-platform, and well-safe penetrating enterprise firewalls are enough to make us feel excited. However, it also has a place where it needs to be improved, such as:

HTTP has a slowerness of data communication, especially the first connection. It is necessary for a Web Server to say the architecture of WebServices and the shortcomings of WebServices, and we will cut into the topic. That is our topic of our discussion:

Web Service Service When Delphi is called

Gossip less, we use a simple example of testing WebMethod Attribute: it is a simple business process that completes a transfer from Customer A to B.

First we create a WebService under .NET Framework1.1, this time .NET will help us automatically create a web application

We need to create a class AttributeTest, which is under namespace Namespace AttributeTesting, then this class will automatically inherit its base class System.Web.Services.Webservice, when we need to spend this web application class settings Its WebServiceAttribute, where basic properties include Description and Namespace

[WebServiceAttribute (Namespace = "http://www.isdoo.com/services",

Description = "Hello Ansel, This Is A Testing Web Service!")]

Public class attributetest: system.web.services.Webservice {

[WebMethodaTRibute "Description Information: Inherited the count method, and overload the name. Execute the money from A users to b users ...", // messagename = "changing messagename", BufferResponse = true, CacheDuration = 1000, EnableSession = true, TransactionOption = TransactionOption.RequiresNew)] public string transMoney (double Money) {try {ContextUtil.EnableCommit (); // Transaction only used to Database operation MoneyInToA (Money);! MoneyOutFromB (); Return "Transaction Successful, Total" Money.toTOString ();} catch (exception e) {contextUtil.Setabort (); return "Transaction Failed! / N / R" E. Message;}} private void MoneyInToA (double Money) {SqlCommand sqlCom = new SqlCommand ( "update budget set Money = Money " Money.ToString () "where Name = 'A'"); databaseAccess myDatabase = new databaseAccess () SQLCOM.CONNECTION = mydatabase.getConnection (); sqlcom.connection.open (); sqlcom.executenonquery (); sqlcom.connection. Close (); // throw new Exception ( "Operation failed when transfer money into A!");} Private void MoneyOutFromB (double Money) {SqlCommand sqlCom = new SqlCommand ( "update budget set Money = Money -" Money.ToString () "where Name = 'B'"); databaseAccess myDatabase = new databaseAccess (); sqlCom.Connection = myDatabase.getConnection (); sqlCom.Connection.Open (); sqlCom.ExecuteNonQuery (); sqlCom.Connection.Close (); // throw new Exception ("Operation Failed When Transfer Money from B!");

}

We need to pay special attention to WebMethodAttribute, this is also our key content, as long as it adds [WebMethodAttribute], even if there is no property inside, then WebService will expose this method (Expose). Customer segment call. Let's talk about its six attributes, including 2 descriptive information properties, 4 functional properties descriptive information properties:

DescriptionMessageName4 functional properties:

BufferResponseCachedurationNableSessionTransactionTionTionTionTransactionOption Of them need to pay attention to MessageName This property It is time to be developed under the .NET platform, if you set the messageName this Attribute, then the client will report an error. This may be a bug, perhaps later version will solve this problem. As for the specific features of these attributes, it will not be described in detail here. Everyone can take a look at the relevant books.

Below I am using the step of Delphi to call WebService:

First, if you only develop call the client, then you only need to create a normal application, then you need to do it, find the SOAPHTTPCLIENT control below toolbar Webserve, then put it on your client application window Body;

Second, you need to set this soaphtpclient's property URL or WSDL. This is your webservice service address.

For example, our current example of the service address is: http://localhost/attributetetesting/attributetesting.asmx

If you want to enter WSDL, it is http://localhost/attributetetesting/attributeTesting.asmx? WSDL

This completes the control settings;

Then we need to introduce the server-side WSDL, you can do it, you can also use the WebServices IMPORTER functionality provided by Delphi.

Finally, you only need to call the introduced WSDL interface. Here our correspondence code is:

Procedure TFORM1.BITBTN1CLICK (Sender: Tobject); var aa: attributetestsoap; // This is the class interface object under WSDL. Request and Accepting Response AA: = httprio2 as attributetestsoap;

BB: = 100.00; Msg: = aa.transmoney (bb); // This is the web service method to invoke the Web service to our web service method WebMethod ShowMessage (END);

OK! That's all!

转载请注明原文地址:https://www.9cbs.com/read-33164.html

New Post(0)