作者: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/