Introduction to the use of WebServices APIs in Symbian study note 8 (Part 1)

Source: Internet
Author: User

(Reprinted -- keep learning later)

According to the information provided in the SDK documentation, this interface seems a bit complicated, including the connection API, description
API and Manager
Three sets of APIs are also involved in some API applications such as XML parsing.

I read its example Program (addressbook under the s60ex directory), which makes me more confused. Why is it different from the usual WebService?

In the SDK documentation, there is a description about csenserviceconnection:

Web
Services includes two different framework models: 1. Identity Based Web Services Framework (ID-WSF).
Framework ID for this is kdefaultidwsfframeworkid ("ID-WSF"). 2. Basic Web
Services Framework. Framework ID is kdefaultbasicwebservicesframeworkid
("WS-I ").

If contract is provided, ID-WSF is used by default.

First, use. Net for a simple WebServices test. Use the helloworld generated by default. The soap description is as follows:
View
Plaincopy to clipboardprint?
<PRE class = CSHARP name = "code"> post
/UIM/pservice. asmx HTTP/1.1

HOST: localhost

Content-Type:
Text/XML; charset = UTF-8

Content-Length: Length

Soapaction: "urn: pservice: helloworld"

<? XML
Version = "1.0" encoding = "UTF-8"?>

<Soap: Envelope
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/">

<Soap: Body>

<Helloworld xmlns = "http: // sharetop/pservice"
/>

</Soap: Body>

</Soap: envelope>

HTTP/1.1 200 OK

Content-Type: text/XML; charset = UTF-8

Content-Length: Length

<? XML version = "1.0"
Encoding = "UTF-8"?>

<Soap: Envelope
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/">

<Soap: Body>

<Helloworldresponse
Xmlns = "http: // sharetop/pservice">

<Helloworldresult> string  
</Helloworldresponse>

</Soap: Body>

</Soap: envelope> </PRE>

View plaincopy
Clipboardprint?

Post/UIM/pservice. asmx http/ 1.1
Host:
Localhost
Content-Type: text/XML; charset = UTF-8

Content-Length:
Length

Soapaction: "urn: pservice: helloworld"

<? XML
Version = "1.0" encoding = "UTF-8"?>

<Soap: Envelope
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/">

<Soap: Body>

<Helloworld
Xmlns = "http: // sharetop/pservice"/>

</Soap: Body>

</Soap: envelope>

HTTP/1.1 200 OK

Content-Type: text/XML; charset = UTF-8

Content-Length:
Length

<? XML version = "1.0" encoding = "UTF-8"?>

<Soap: Envelope
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/">

<Soap: Body>

<Helloworldresponse
Xmlns = "http: // sharetop/pservice">

<Helloworldresult> string

</Helloworldresponse>

</Soap: Body>
 

</Soap: envelope>

Post/UIM/pservice. asmx
HTTP/1.1

HOST: localhost

Content-Type: text/XML;
Charset = UTF-8

Content-Length: Length

Soapaction:
"Urn: pservice: helloworld"
<? XML version = "1.0"
Encoding = "UTF-8"?>
<Soap: Envelope
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/">
<Soap: Body>
 
<Helloworld xmlns = "http: // sharetop/pservice"
/>
</Soap: Body>
</Soap: envelope>
HTTP/1.1 200
OK
Content-Type: text/XML; charset = UTF-8
Content-Length:
Length
<? XML version = "1.0" encoding = "UTF-8"?>
<Soap: Envelope
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/">
<Soap: Body>
 
<Helloworldresponse xmlns = "http: // sharetop/pservice">

<Helloworldresult> string
</Helloworldresponse>
</Soap: Body>
</Soap: envelope>

Let's create a ws client instance by ourselves. Use the Wizard to generate a helloworld application. For the convenience of research, we do not plan to make any interface. All outputs are output to the log file through logs.

To facilitate encoding, we add a class webengine, which should be derived from csenbasefragment and msenserviceconsumer. The statement is as follows:

View plaincopy to clipboardprint?

Class cwebengine: Public
Csenbasefragment, public msenserviceconsumer

{

Public:
 

~ Cwebengine ();
Static cwebengine * newl ();
Static
Cwebengine * newlc ();

Void connectl ();

Void sayhello ();

// From msenserviceconsumer

Virtual void
Handlemessagel (const tdesc8 & amessage );

Virtual void
Handleerrorl (const tint aerrorcode, const tdesc8 & aerror );

Virtual void setstatus (const tint AStatus );

Protected:

// From csenbasefragment

Virtual void startelementl (const
Tdesc8 & ansuri, const tdesc8 & alocalname, const tdesc8 & aqname,
Const XML: rattributearray & aattrs );

Virtual void
Endelementl (const tdesc8 & ansuri, const tdesc8 & alocalname, const
Tdesc8 & aqname );

PRIVATE:

Cwebengine ();

Void
Constructl ();

Public:

Chelloworldresult * delegate;

PRIVATE:

Csenserviceconnection * iconnection;

Csenxmlservicedescription * isession;

Csenxmlreader *
Ixmlreader;

};

Class cwebengine: Public csenbasefragment,
Public msenserviceconsumer

{

Public:


~ Cwebengine ();

Static cwebengine * newl ();

Static
Cwebengine * newlc ();

Void connectl ();

Void
Sayhello ();

// From msenserviceconsumer

Virtual
Void handlemessagel (const tdesc8 & amessage );

Virtual void
Handleerrorl (const tint aerrorcode, const tdesc8 & aerror );


Virtual void setstatus (const tint AStatus );

Protected:


// From csenbasefragment

Virtual void startelementl (const
Tdesc8 & ansuri, const tdesc8 & alocalname, const tdesc8 & aqname,
Const XML: rattributearray & aattrs );


Virtual void endelementl (const tdesc8 & ansuri, const tdesc8 &
Alocalname, const tdesc8 & aqname );

PRIVATE:


Cwebengine ();

Void constructl ();

Public:


Chelloworldresult * delegate;

PRIVATE:


Csenserviceconnection * iconnection;

Csenxmlservicedescription *
Isession;

Csenxmlreader *
Ixmlreader;

};

In addition to implementing the methods of two parent classes, you also need to add connectl () for connection and sayhello () for calling remote methods. The delegate is
Example of the chelloworldresult class. This class is also derived from csendomfragment, indicating that it corresponds to a piece of XML content. We use it to process the result, that is, the content under the helloworldresponse label.

The implementation logic of this webengine is: first initialize the WS client in connectl, and get the current status value in the setstatus callback if it is
Ksenconnectionstatusready
You can call sayhello to execute the WS method. Then, parse the result (byte stream of XML content) in the handlemessagel callback and parse it.
The XML callback is the two startelement and endelement.

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.