作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/
1.SOAP消息:
2.WSDL
3.Web Service
4.实例:
1)Eclipse 以及Ant建立一个简单的Web Service,以演示Web Service的基本开发过程:http://blog.csdn.net/gnuhpc/archive/2009/12/22/5047951.aspx
2)QT SOAP 的一个实例:
开始学习时,看到网上有朋友说这个库难用,我觉得还好吧,蛮好使的,下边写一个例子。
今天早上写的,远程访问这个http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx?op=getStockInfoByCode Web service,获得股票信息。
简单了拖拽了一个界面,如下:
具体代码如下,几个关键的地方我用黑体加粗进行了注释:
main.cpp:
#include
#include "stockws.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
StockWS w;
w.show();
return a.exec();
}
stockws.cpp:
#include "stockws.h"
#include
StockWS::StockWS(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags), http(this)
{
ui.setupUi(this);
ui.idline;
connect(&http, SIGNAL(responseReady()), SLOT(getResponse()));
connect(ui.idline, SIGNAL(returnPressed()), SLOT(submitRequest()));
connect(ui.RequestStock, SIGNAL(clicked()), SLOT(submitRequest()));
http.setAction("/"http://WebXml.com.cn/getStockInfoByCode/"");// 设置SOAPACTION
http.setHost("webservice.webxml.com.cn");// 设置HOST
}
StockWS::~StockWS()
{
}
void StockWS::submitRequest()
{
QtSoapQName name;
// Check that ID is provided or not
if (ui.idline->text() == "") {
QMessageBox::warning(this, tr("Missing Stock ID"),
tr("Please Enter the Stock ID for query"));
return;
}
// Generate request. Details about how to generate a proper
QtSoapMessage request;
request.setMethod(QtSoapQName("getStockInfoByCode", "http://WebXml.com.cn/"));// 设置方法和所在命名空间=>xmlns=http://WebXml.com.cn/
request.addMethodArgument("theStockCode", "", ui.idline->text()); // 设置方法的参数
// Submit the method request to the web service.
http.submitRequest(request, "/WebServices/ChinaStockWebService.asmx"); //设置POST字段
// Set the cursor to wait mode.
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
}
void StockWS::getResponse()
{
int i;
// Set cursor back to normal shape.
QApplication::restoreOverrideCursor();
// Reset resultView.
ui.stockResult->clear();
// Get the response, check for error.
const QtSoapMessage &resp = http.getResponse();
if (resp.isFault()) {
ui.stockResult->setText((resp.faultString().value().toString()));
return;
}
// Extract the return value from this method response, check for
// errors.
const QtSoapType &res = resp.returnValue();
if (!res.isValid()) {
ui.stockResult->append("Invalid return value");
return;
}
ui.stockResult->setText(res[0].toString());
for (i=0;i
{
ui.stockResult->append(res[i].toString()+"/n");
}
}
输入一个股票:sh500006,基金裕阳的股票代码,稍等片刻就得到如下结果:
3)gsoap使用:
我想起三月份的时候拿Gsoap和Libfetion写了一个获取股票实时信息并且发短信指定人的例子,基本功能都实现了,有时间具体完善一下后放上来~
作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/
作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/
除非另有声明,本网站采用知识共享“署名 2.5 中国大陆”许可协议授权。
![clip_image002[4] clip_image002[4]](https://yqfile.alicdn.com/img_f983009c54dcba84660d57e9f940b4e8.png?x-oss-process=image/resize,w_1400/format,webp)
![clip_image004[4] clip_image004[4]](https://yqfile.alicdn.com/img_bf64e46959cd908eec7bd53658eaa83a.png?x-oss-process=image/resize,w_1400/format,webp)
![clip_image006[4] clip_image006[4]](https://yqfile.alicdn.com/img_40fbef93e3d9d054fc4107cb46a61121.png?x-oss-process=image/resize,w_1400/format,webp)
![clip_image008[4] clip_image008[4]](https://yqfile.alicdn.com/img_a2c39d031d962838b7f9370a5df57e54.png?x-oss-process=image/resize,w_1400/format,webp)
![clip_image010[4] clip_image010[4]](https://yqfile.alicdn.com/img_a355023140a3e05c6e95e957cdcf6663.png?x-oss-process=image/resize,w_1400/format,webp)
![clip_image012[4] clip_image012[4]](https://yqfile.alicdn.com/img_5e45cf0a1f6a1097da5afab5a0b46913.png?x-oss-process=image/resize,w_1400/format,webp)
![clip_image014[4] clip_image014[4]](https://yqfile.alicdn.com/img_f158dd0c869b78d3314aa25e11bb6190.png?x-oss-process=image/resize,w_1400/format,webp)
![clip_image016[4] clip_image016[4]](https://yqfile.alicdn.com/img_8a2abdae24bb8556188e11c754c28913.png?x-oss-process=image/resize,w_1400/format,webp)
![clip_image018[4] clip_image018[4]](https://yqfile.alicdn.com/img_4d600d6c27d2fc472c4ee32959e71f48.png?x-oss-process=image/resize,w_1400/format,webp)