(转载 --留着以后学习)
从SDK文档中提供的资料来看这个接口似乎有点复杂,包括了Connection API、Description API和Manager API三套东西,此外还涉到了XML的解析之类的一些API的应用。阅读了一下它的例子程序(S60Ex目录下的AddressBook),让我更晕乎了。怎么跟自己平时使用的WebService不一样了?在SDK文档中关于CSenServiceConnection有这么一段描述:Web Services包括两种不同的框架模型: 1. Identity Based Web Services Framework (ID-WSF). The framework ID for this is KDefaultIdWsfFrameworkID ("ID-WSF"). 2. Basic Web Services Framework. Framework ID is KDefaultBasicWebServicesFrameworkID ("WS-I").如果提供了Contract则缺省使用ID-WSF。首先用.NET做一个简单的WebServices来测试,就用缺省产生的HelloWorld吧。很简单的,它的SOAP描述如下: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</HelloWorldResult> </HelloWorldResponse> </soap:Body> </soap:Envelope></PRE> view plaincopy to clipboardprint?POST /uim/PService.asmx HTTP/1.1 Host: localhostContent-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</HelloWorldResult> </HelloWorldResponse> </soap:Body> </soap:Envelope> POST /uim/PService.asmx HTTP/1.1Host: localhostContent-Type: text/xml; charset=utf-8Content-Length: lengthSOAPAction: "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 OKContent-Type: text/xml; charset=utf-8Content-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</HelloWorldResult> </HelloWorldResponse> </soap:Body></soap:Envelope>下面我们自己来做一个WS的客户端实例吧。先用向导生成一个HelloWorld应用,为了研究方便,我们不打算做什么界面,所有的输出都通过LOG输出到日志文件。为了编码方便,我们增加一个类WebEngine,它应该派生于CSenBaseFragment和MSenServiceConsumer。声明如下: 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 Xml::RAttributeArray& aAttrs); virtual void EndElementL(const TDesC8& aNsUri,const TDesC8& aQName);private: CWebEngine(); void ConstructL();public: CHelloWorldResult * delegate;private: CSenServiceConnection* iConnection; CSenXmlServiceDescription* iSession; CSenXmlReader* iXmlReader;};除了实现两个父类的方法以外,还要增加ConnectL()用来连接,SayHello()用来调用远程方法。那个delegate是一个 CHelloWorldResult类的实例,这个类同样派生于CSenDomFragment,说明它对应一段XML内容,我们用它来处理结果,就是那个HelloWorldResponse标签下的内容。这个WebEngine的实现逻辑是:先在ConnectL中初始化WS客户端,在SetStatus回调中取当前状态值如果为 KSenConnectionStatusReady ,则可以调用SayHello去执行那个WS的方法,然后,在HandleMessageL回调中将得到的结果(XML内容的字节流)去解析一下,解析 XML的回调就是那两个StartElement和EndElement。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。