Symbian Learning Notes (21)-There is also this tool wsdl2cpp, access to WebService is also very simple

Source: Internet
Author: User
Tags command line header wsdl

In the forum to see someone ask the use of Wsdl2cpp to generate code to know that the original Symbian provides an auxiliary tool to generate WebService client code, Compared to the last time I toss the reference addressbook example to do WebService client is much simpler, similar to the use of gSOAP.

First, go to forum.nokia.com.cn to search for the WSDL-TO-C++_FOR_S60, which is a tool for Carbice vs, but can also be installed independently, using the command line to generate the required code. Download the installation can be.

The second step, run its wsdl2cpp tool, get some source code, but it is a little more than gSOAP retarded, can not directly give a WSDL URL, so it is best to download the WSDL to the local, give it a filename can:

Wsdl2cpp--callback-class pserviceconsumer--include-dir. \work\inc--source-dir. \work\src pservice.wsdl

In this way we will get the header and source files generated under the WORK/SRC and Work/inc under the current directory, and the principle of implementation is still using Symbian's built-in Web Service API. Get the code into the project.

The third step, the project added code, modify MMP, and directly using these APIs, in short, this tool is only to help us generate the source code framework, more convenient. But a little bit of extra growth is:

LIBRARY XmlDataBinding.lib userinclude \epoc32\include\libc userinclude \epoc32\include\xmldatabinding

Here the XmlDataBinding is something new, so before you need to install, after installing the wsdl-to-c++ tool, there is a xmldatabinding.zip in its directory, open the solution to the corresponding EPOC32 directory. It includes Lib and some header files.

And, in the mobile phone, should be xmldatabinding.sis also installed, from this point of view, seems to be a little more trouble than gSOAP.

The fourth step, now start to modify the code, very simple.

View Plaincopy to Clipboardprint?

Private

Data

Chellowsthreeappview*iappview;

Cpserviceservice*iservice;

Cpserviceconsumer*iobserver;

private:
  // Data
  CHelloWSThreeAppView* iAppView;
  CPServiceService * iService;
  CPServiceConsumer * iObserver;

Add IService and IObserver to the header file, there are two steps in the CPP, one is to initialize the connection, and the other is to invoke the method remotely:

View Plaincopy to Clipboardprint?

Here, initialize the code.

CSENXMLSERVICEDESCRIPTION*PSERVICEDESC=CSENXMLSERVICEDESCRIPTION::NEWLC (Kserviceendpoint,knulldesc8 ());

Pservicedesc->setframeworkidl (Kdefaultbasicwebservicesframeworkid);

IOBSERVER=CPSERVICECONSUMER::NEWLC ();

ISERVICE=CPSERVICESERVICE::NEWLC (*IOBSERVER,*PSERVICEDESC);

_lit (Kstr, "initservice.");

LOG (KSTR);

Here the remote calling code

if (Iobserver->istatus==ksenconnectionstatusready) {

Rhelloworldahello;

RHELLOWORLDRESPONSEAHELLORESP;

TRAPD (ERROR,AHELLORESP=ISERVICE->HELLOWORLDL (Ahello));

if (Error) {

Rdebug::P rintf ("error%d", error);

}

tbuf<64>buf;

Buf. Copy (Ahelloresp.ihelloworldresult);

_lit (KSTR, "resultis%s");

Log_format ((KSTR,BUF));

}

//这里初始化代码
CSenXmlServiceDescription *pServiceDesc = CSenXmlServiceDescription::NewLC(KServiceEndpoint, KNullDesC8());
pServiceDesc->SetFrameworkIdL(KDefaultBasicWebServicesFrameworkID);
iObserver = CPServiceConsumer::NewLC();
iService = CPServiceService::NewLC(*iObserver,*pServiceDesc);
_LIT(KStr,"Init service.");
LOG(KStr);
//这里远程调用代码
if(iObserver->iStatus==KSenConnectionStatusReady){
RHelloWorld aHello;
RHelloWorldResponse aHelloResp;
TRAPD(error,aHelloResp=iService->HelloWorldL(aHello));
if(error){
RDebug::Printf("error %d",error);
}
TBuf<64> buf;
buf.Copy(aHelloResp.iHelloWorldResult);
_LIT(KStr,"result is %S");
LOG_FORMAT((KStr,buf));
}

That's fine, of course. To delete these member variables during the destructor.

To sum up, in fact, I use three kinds of methods to invoke Web service, are the simplest helloworld, in comparison, or gsoap more convenient.

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.