使用Delphi 6 + SOAP 开发web service程序

在论坛看到个文章:
主题: 请帮忙一下关于Web Service 接口规范


单位用了一个Web程序,上边有系统要的信息。给了个Web Service 接口规范。我要怎么办才能得到信息

。一点头绪也没有。希望高人给点意见。用C++Builder 6

接口规范内容:
1、服务定位:
http://server_ip_address:port/services/CorpEntityService
server_ip_address-系统的服务器地址
port-服务的端口
2、输入参数规范:
com.bdcc.ncms.webservice.security.User 对象-主要用于验证用户身份,由系统提供给用户,包括下
面的属性:
username-String 用户名
Password-String 密码

com.bdc.ncms.corpentity.dto. CorpEntityWsparamDTO 对象-主要封闭了获取对象信息的必要信息,包

括:
cardNo-String 卡号
PersonName-String 姓名

3、输出参数规范
输入参数主要由对象:com.bdcc.ncms.corpentity.dto. CorpEntity WsresultDTO 封装,包括下面的属性
CardNo-String 卡号
PersonName-Long 证书号
PersonId-Long 标识ID
dateOfBirth-Date 生日
status-String 访问状态 0成功/-1失败。
errorCode-错误编码信息,当status为-1时,参考此属性

有以上这些东西怎样用C++Builder取得我要的信息。该用什么控件。要怎么办。谁能指点一二。


这个接口写的也太省略了,只是写出了输入和输出参数,只看这一部分内容怎么可能写出接口来?!要是写接口文档的真这样写,那可真应该打pp了。grin
利用google查了下,发现yshff (子夜时分)在csdn.net上还有一个帖子:
C++Builder+WSDL怎么设计程序。


由WSDL文件生成的C++builder程序见以下:
//—-主文件CorpEntityService.cpp—
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : G:\web\wsdl\CorpEntityService.wsdl
// Encoding : UTF-8
// Version : 1.0
// (2007-3-28 21:09:17 – $Revision: 1.0.1.0.1.82 $)
// ************************************************************************ //

#include
#pragma hdrstop

#if !defined(CorpEntityServiceH)
#include “CorpEntityService.h”
#endif

namespace NS_CorpEntityService {

_di_CorpEntityEndpoint GetCorpEntityEndpoint(bool useWSDL, AnsiString addr)
{
static const char* defWSDL= “G:\web\wsdl\CorpEntityService.wsdl”;
static const char* defURL = “http://220.165.93.74:8080/ncms/services/CorpEntityService”;
static const char* defSvc = “CorpEntityEndpointService”;
static const char* defPrt = “CorpEntityService”;
if (addr==”")
addr = useWSDL ? defWSDL : defURL;
THTTPRIO* rio = new THTTPRIO(0);
if (useWSDL) {
rio->WSDLLocation = addr;
rio->Service = defSvc;
rio->Port = defPrt;
} else {
rio->URL = addr;
}
_di_CorpEntityEndpoint service;
rio->QueryInterface(service);
if (!service)
delete rio;
return service;
}

__fastcall CorpEntityWSResultDTO::~CorpEntityWSResultDTO()
{
delete FdateOfBirth;
}

// ************************************************************************ //
// This routine registers the interfaces and types used by invoke the SOAP
// Service.
// ************************************************************************ //
static void RegTypes()
{
/* CorpEntityEndpoint */
InvRegistry()->RegisterInterface(__interfaceTypeinfo(CorpEntityEndpoint), L”http://com.bdcc.ncms.webservice.corpentity.CorpEntityService”, L”UTF-8″);
InvRegistry()->RegisterDefaultSOAPAction(__interfaceTypeinfo(CorpEntityEndpoint), L”");
/* User */
RemClassRegistry()->RegisterXSClass(__classid(User), L”http://security.webservice.ncms.bdcc.com”, L”User”);
/* CorpEntityWSParamDTO */
RemClassRegistry()->RegisterXSClass(__classid(CorpEntityWSParamDTO), L”http://dto.corpentity.ncms.bdcc.com”, L”CorpEntityWSParamDTO”);
/* CorpEntityWSResultDTO */
RemClassRegistry()->RegisterXSClass(__classid(CorpEntityWSResultDTO), L”http://dto.corpentity.ncms.bdcc.com”, L”CorpEntityWSResultDTO”);
}
#pragma startup RegTypes 32

}; // NS_CorpEntityService

///////////————CorpEntityService.h文件——–
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : G:\web\wsdl\CorpEntityService.wsdl
// Encoding : UTF-8
// Version : 1.0
// (2007-3-28 21:09:17 – $Revision: 1.0.1.0.1.82 $)
// ************************************************************************ //

#ifndef CorpEntityServiceH
#define CorpEntityServiceH

#include
#include
#include
#include

namespace NS_CorpEntityService {

// ************************************************************************ //
// The following types, referred to in the WSDL document are not being represented
// in this file. They are either aliases[@] of other types represented or were referred
// to but never[!] declared in the document. The types from the latter category
// typically map to predefined/known XML or Borland types; however, they could also
// indicate incorrect WSDL documents that failed to declare or import a schema type.
// ************************************************************************ //
// !:string – “http://schemas.xmlsoap.org/soap/encoding/”
// !:long – “http://schemas.xmlsoap.org/soap/encoding/”
// !:NcmsBaseDTO – “http://dto.corpentity.ncms.bdcc.com”
// !:dateTime – “http://www.w3.org/2001/XMLSchema”

class User;
class CorpEntityWSParamDTO;
class CorpEntityWSResultDTO;

// ************************************************************************ //
// Namespace : http://security.webservice.ncms.bdcc.com
// ************************************************************************ //
class User : public TRemotable {
private:
AnsiString Fpassword;
AnsiString FuserName;
public:
__published:
__property AnsiString password = { read=Fpassword, write=Fpassword };
__property AnsiString userName = { read=FuserName, write=FuserName };
};

// ************************************************************************ //
// Namespace : http://dto.corpentity.ncms.bdcc.com
// ************************************************************************ //
class CorpEntityWSParamDTO : public TRemotable {
private:
AnsiString FcardNo;
__int64 FpersonCode;
AnsiString FpersonName;
public:
__published:
__property AnsiString cardNo = { read=FcardNo, write=FcardNo };
__property __int64 personCode = { read=FpersonCode, write=FpersonCode };
__property AnsiString personName = { read=FpersonName, write=FpersonName };
};

// ************************************************************************ //
// Namespace : http://dto.corpentity.ncms.bdcc.com
// ************************************************************************ //
class CorpEntityWSResultDTO : public TRemotable {
private:
AnsiString Faddress;
AnsiString FcardNo;
TXSDateTime* FdateOfBirth;
AnsiString FerrorCode;
AnsiString Fidentification;
AnsiString FisActive;
__int64 FpersonCode;
__int64 FpersonId;
AnsiString FpersonName;
AnsiString Fsex;
AnsiString Fstatus;
public:
__fastcall ~CorpEntityWSResultDTO();
__published:
__property AnsiString address = { read=Faddress, write=Faddress };
__property AnsiString cardNo = { read=FcardNo, write=FcardNo };
__property TXSDateTime* dateOfBirth = { read=FdateOfBirth, write=FdateOfBirth };
__property AnsiString errorCode = { read=FerrorCode, write=FerrorCode };
__property AnsiString identification = { read=Fidentification, write=Fidentification };
__property AnsiString isActive = { read=FisActive, write=FisActive };
__property __int64 personCode = { read=FpersonCode, write=FpersonCode };
__property __int64 personId = { read=FpersonId, write=FpersonId };
__property AnsiString personName = { read=FpersonName, write=FpersonName };
__property AnsiString sex = { read=Fsex, write=Fsex };
__property AnsiString status = { read=Fstatus, write=Fstatus };
};

// ************************************************************************ //
// Namespace : http://com.bdcc.ncms.webservice.corpentity.CorpEntityService
// transport : http://schemas.xmlsoap.org/soap/http
// style : rpc
// binding : CorpEntityServiceSoapBinding
// service : CorpEntityEndpointService
// port : CorpEntityService
// URL : http://localhost:8080/ncms/services/CorpEntityService
// ************************************************************************ //
__interface INTERFACE_UUID(“{E9115789-3B20-0C6B-37C5-35E5B5BE203D}”) CorpEntityEndpoint : public IInvokable
{
public:
virtual CorpEntityWSResultDTO* getCorpEntity(const User* user, const CorpEntityWSParamDTO* dto) = 0;
};
typedef DelphiInterface _di_CorpEntityEndpoint;

_di_CorpEntityEndpoint GetCorpEntityEndpoint(bool useWSDL=false, AnsiString addr=”");

#endif // __CorpEntityService_h__

}; // NS_CorpEntityService

#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace NS_CorpEntityService;
#endif

谁能讲解一下。我该怎么调用里边的方法。该用什么控件。怎么调用。谢谢。


看了这个C++builder根据WSDL导入生成的接口文件,知道是怎么回事了,就是要做一个SOAP/Web Service的程序。看了这个熟悉的C++ Builder代码,又再看了一下接口的说明,发现文档编写的几个疏忽:
接口文档只说明了输入输出参数,但是com.bdc.ncms.corpentity.dto. CorpEntityWsparamDTO的写法并不适合接口文档。
接口文档缺乏编写接口程序的要求,根据C++ Builder接口程序看出,接口程序需要SOAP+Complex Type 技术。
接口文档缺乏Web Service Client 调用函数,仔细往下面看:
virtual CorpEntityWSResultDTO* getCorpEntity(const User* user, const CorpEntityWSParamDTO* dto) = 0;
 
SOAP(Simple Object Access Protocol) 是一个标准,目前的很多Web Service 都使用这个来交换数据,目前都是使用http/https。Delphi在开发SOAP程序有多种选择,灵活性非常高,做一个简单的Web Service 程序也就是几分钟的事情。

CodeGerar 发布了 Delphi 2007 for Win32,高兴啊envy

打赏