On the issue of the Web service services written under C # when Delphi is lowered

Source: Internet
Author: User
Tags tostring web services wsdl firewall
web| questions about the Web service services written under C # when Delphi is lowered

First of all, I think it is necessary to develop the webservice under the. NET Platform for a more comprehensive exposition, the first generation of Web service in the context of e-commerce, some problems through the traditional means is not easy to solve, such as in the application of business communications, data exchange, The use of DCOM, CORBA, and other binary mechanism of things have not worked, let's not say they are limited by the platform, such as DCOM (distribute Common Objects Model) can only be done under the Windows platform, and CORBA (Common Objects Request Broker Architecture) is just the product of the Java platform. It is more difficult for them to implement data communication between applications.

In this context, Web Services emerged as a good solution to cross language, cross-platform and good and secure penetration of the enterprise firewall. Its architecture is broadly divided into five levels:

Data communication under HTTP (Hypertext Transfer Protocol) channel
XML (extensable Markup Language) Data representation
Data encapsulation of SOAP (simple Objects Access Protocol)
Description Language format for WSDL (webservices Description Language)
UDDI (Universal Description and Discovery Integration) Unified description, Discovery, and integration
As it has the advantage of Cross-language, cross-platform, and good and secure penetration of the corporate firewall is enough to make us feel excited. But there are also areas where improvements are needed, such as:

HTTP data communication exists at a slower rate, especially for the first connection.
The additional overhead of needing a Web server
After talking about the webservices architecture and its pros and cons, we cut to the chase, and that's the topic of our discussion:

The problem of WEB service services when Delphi is lowered

Less gossip, we use a simple example that examines the attributes of WebMethod: It is a simple business process that completes a transfer from customer A to B.

First we create a webservice under. NET FrameWork1.1, when. NET will help us create a Web application automatically

We need to create a class attributetest, which is under the namespace namespace attributetesting, so this class will automatically inherit its base class System.Web.Services.WebService, when it comes to spending, we can set its webserviceattribute on this Web application class, 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
{

[WebMethodAttribute (description=) Description: Inherits the Count method and overloads the name. The execution is to transfer money from a user to B users ... ",
Messagename= "Changing MessageName",
Bufferresponse=true,
cacheduration=1000,
Enablesession=true,
Transactionoption=transactionoption.requiresnew)]
public string Transmoney (double)
{
Try
{
Contextutil.enablecommit ();//transaction only used to Database operation!
Moneyintoa (Money);
Moneyoutfromb (Money);
ContextUtil.SetComplete ();
Return "Transaction successful,total" +money.tostring ();
}
catch (Exception e)
{
ContextUtil.SetAbort ();
Return "Transaction failed! \n\r "+e.message;
}
}
private void Moneyintoa (double)
{
SqlCommand sqlcom = new SqlCommand ("Update budget set money=money+" +money.tostring () + "where name= '");
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)
{
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!");
}

}

One of the things that we need to pay special attention to, WebMethodAttribute, is that this is what we need to talk about this time, just add [WebMethodAttribute] to a method, even if it doesn't have any attributes, Then webservice will expose the method (expose) to the client segment caller. Here's a description of its 6 properties, including 2 descriptive information properties, 4 feature properties

Descriptive information properties:

Description
MessageName
4 Functional Properties:

BufferResponse
CacheDuration
EnableSession
TransactionOption
One of the things we need to pay attention to messagename This attribute is that Delphi calls the webservice when it is developed under the. NET platform, if you set the attribute of MessageName, then the client invokes the error. This may be a bug, and perhaps the later version will solve the problem. The specific functions of these attributes are no longer described here in detail. You can go and see the relevant books.

Below I put the Delphi call WebService steps to enumerate:

First of all, if you're just developing the calling client, then you just need to create an ordinary application, and then what you need to do is find the Soaphttpclient control under the toolbar webservices and put it on your client application form.

The second is that you need to set the Soaphttpclient property URL or WSDL, which is your WebService service address.

For example, the service address of our current example is: Http://localhost/AttributeTesting/AttributeTesting.asmx

If you want to enter the WSDL, then it's http://localhost/AttributeTesting/AttributeTesting.asmx?wsdl.

This completes the control settings;

Then we need to introduce the server-side WSDL, you can do it by hand, or you can use the WebServices importer function provided by Delphi to introduce.

Finally, you only need to invoke the interface of the introduced WSDL. Our corresponding code here is:

Procedure Tform1.bitbtn1click (Sender:tobject);
Var
aa:attributetestsoap;//This is the class interface object under WSDL
msg:widestring;
bb:double;
Begin
HTTPRIO2 is actually called the proxy class, it is responsible for data transmission send request and accept response
Aa:=httprio2 as Attributetestsoap;

bb:=100.00;
Msg:=aa.transmoney (BB)//This is the Web service method exposed to us by invoking Web services WebMethod
ShowMessage (msg);
End


Ok! That ' s all!




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.