Introduction to the use of WebServices APIs in Symbian Study Notes 8)

Source: Internet
Author: User
Tags call back

Let's continue with the previous step. Now let's look at the specific code. First, the implementation of connectl:

View plaincopy to clipboardprint?

Void
Cwebengine: connectl ()

{

Csenxmlservicedescription *
Pattern = csenxmlservicedescription: newlc ();

Pattern-> setframeworkidl (kdefaultbasicwebservicesframeworkid );
 

Pattern-> setendpointl (kwsendpoint );

Delete iconnection;
 

Iconnection = NULL;

Iconnection =
Csenserviceconnection: newl (* This, * pattern );
 

Cleanupstack: popanddestroy (pattern );
}

Void
Cwebengine: connectl ()

{


Csenxmlservicedescription * pattern = csenxmlservicedescription: newlc ();


Pattern-> setframeworkidl (kdefaultbasicwebservicesframeworkid );


Pattern-> setendpointl (kwsendpoint );

Delete
Iconnection;

Iconnection = NULL;


Iconnection = csenserviceconnection: newl (* This, * pattern );


Cleanupstack: popanddestroy (pattern );


}

Note that, unlike the addressbook example, we declare that the different framework types are
Kdefabasbasicwebservicesframeworkid. In this way, you only need to provide the endpoint instead of the contract.
The value of kwsendpoint is declared before CPP: _ lit8 (kwsendpoint, "http: // 192.168.0.201/UIM
/Pservice. asmx ");

Csenserviceconnection: Two Parameters of newl. One is that msenserviceconsumer is responsible for processing the callback, and the other is csenxmlservicedescription, which is responsible for parameter configuration.

In the callback setstatus, I simply print the status value.

Let's look at the implementation of sayhello. In this function, we need to encapsulate the SOAP message package. Then I encountered the annoying problem of using the Symbian webserviceapi: The Original Soap package should be encapsulated by myself! Similarly, the soap results must be parsed by yourself !!
View
Plaincopy to clipboardprint?

Void cwebengine: sayhello ()
{
 

If (iconnectionstate = 1 ){

// Send

Csensoapenvelope * Env = csensoapenvelope: newl ();
 

Cleanupstack: pushl (ENV );
 

Env-> setsoapactionl (kwscontract );

Env-> bodyl (). addelementl (kwsnamespace, kwshelloworld );
 

Iconnection-> sendl (* env );
 

Cleanupstack: popanddestroy (ENV );
}

}

Void cwebengine: sayhello ()

{


If (iconnectionstate = 1 ){

// Send


Csensoapenvelope * Env = csensoapenvelope: newl ();

 
Cleanupstack: pushl (ENV );

Env-> setsoapactionl (kwscontract );


Env-> bodyl (). addelementl (kwsnamespace, kwshelloworld );


Iconnection-> sendl (* env );


Cleanupstack: popanddestroy (ENV );


}


}

Fortunately, helloworld does not require parameters, so this soap request is still simple. Note that the kwscontract of the setsoapactionl function is the "urn: pservice: helloworld"
(See the description of the SOAP request in the previous article ). Because csensoapenvelope is also derived from csenbasefragment
So its body can also add lower-level nodes, and the above Code is easy to understand.

After calling iconnection-> sendl, the access point is displayed, indicating that the network is connected. After the result is obtained, we call back the processing result in handlemessagel.
View
Plaincopy to clipboardprint?

Void cwebengine: handlemessagel (const
Tdesc8 & amessage)

{
 

Rdebug: printf ("========================= handlemessagel ");
 

Log_all (amessage );

Setreader (* ixmlreader );
 

Parsel (amessage );

}

Void
Cwebengine: handlemessagel (const tdesc8 & amessage)

{

 
Rdebug: printf ("========================= handlemessagel ");


Log_all (amessage );


Setreader (* ixmlreader );

Parsel (amessage );


}

Here we will hand over the obtained results (the XML content of the complete soap response) to ixmlreader for parsing, so at this time there will be two other callbacks startelement and endelement. Note that ixmlreader Initialization is completed in webengine constructl:
View
Plaincopy to clipboardprint?

Void cwebengine: constructl ()

{
 

Log_open ();

 
Csenbasefragment: baseconstructl (kqueryresponselocalname );


Ixmlreader = csenxmlreader: newl ();

}

Void
Cwebengine: constructl ()

{


Log_open ();


Csenbasefragment: baseconstructl (kqueryresponselocalname );


Ixmlreader = csenxmlreader: newl ();


}

First, we call baseconstructl to construct an XML node that is a helloworldresponse label because it is derived from csenbasefragment. The second is to construct an ixmlreader instance.

Next we will continue with the XML parsing callback processing:
View
Plaincopy to clipboardprint?

Void cwebengine: startelementl (const
Tdesc8 & ansuri, const tdesc8 & alocalname, const tdesc8 & aqname,
Const XML: rattributearray & aattrs)

{

Rdebug: printf ("====================== startelement ");

_ Increment (kfmt, "startelement (% s )");

Log_format (kfmt, alocalname ));
 

If (alocalname = kqueryresponselocalname ){

Delegate =
Chelloworldresult: newl (ansuri, alocalname, aqname );

Cleanupstack: pushl (delegate );

Delegateparsingl (* delegate );

Cleanupstack: Pop (delegate );

}

}

Void cwebengine: endelementl (const
Tdesc8 & ansuri, const tdesc8 & alocalname, const tdesc8 & aqname)

{

Rdebug: printf ("========================= endelement ");

_ Increment (kfmt, "endelement (% s )");

Log_format (kfmt, alocalname ));

Csenbasefragment: endelementl (ansuri, alocalname, aqname );

}

Void cwebengine: startelementl (const tdesc8 & ansuri,
Const tdesc8 & alocalname, const tdesc8 & aqname, const
XML: rattributearray &
Aattrs)

{

Rdebug: printf ("====================== startelement ");

_ Increment (kfmt, "startelement
(% S )");

Log_format (kfmt, alocalname ));

If (alocalname = kqueryresponselocalname ){

Delegate =
Chelloworldresult: newl (ansuri, alocalname, aqname );

Cleanupstack: pushl (delegate );

Delegateparsingl (* delegate );

Cleanupstack: Pop (delegate );

}

}

Void
Cwebengine: endelementl (const tdesc8 & ansuri, const tdesc8 & alocalname,
Const tdesc8 &
Aqname)

{

Rdebug: printf ("========================= endelement ");

_ Commit (kfmt, "endelement
(% S )");

Log_format (kfmt, alocalname ));

Csenbasefragment: endelementl (ansuri,
Alocalname,
Aqname );

}

There is nothing to say about this endelement. I just need to adjust Lao Tzu's endelement. But the startelement function.
When the helloworldresponse label is assigned to the delegate to process the lower-level node, that is, the XML content is handled by the chelloworldresult class.

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.