【IT168技术文档】
下面我们来看第二部分的设计开发:
1:新建一个C++Builder项目
2:新建一个webservice栏目的wsdl import.
3:确定以后可以看到页面
4:这里是关键地方,输入 Location of WSDL File or URL
http://localhost:2003/WebSite1/NewsPublish.asmx 这是刚才使用VS2005开发的WebService路径,我们现在将他输入,
会发现提示错误End tag 'ul' does not match the start tag 'p' ,应该怎么解决呢?
我们需要修改 上面传入的URL路径为
http://localhost:2003/WebSite1/NewsPublish.asmx?wsdl既可以。
5:系统为我们生成了很多代码。下面我来分析一下部分关键代码。
由于开始采用C++Builder6进行开发的,可是总会出现一些灵异现象。后来又采用了C++Builder2007处理,才结果比较正常了。
系统自动生成了文件:
NewsPublish.h 和 NewsPublish.cpp两个文件。
上面的这个类,我们发现很熟悉,这是我们使用了Seriaziable的一个.NET类,将用来返回用户数据的一个自定义数据类型。class UserInfo : public TRemotable { private: WideString Fusername; bool Fusername_Specified; WideString Fpassword; bool Fpassword_Specified; void __fastcall Setusername(int Index, WideString _prop_val) { Fusername = _prop_val; Fusername_Specified = true; } bool __fastcall username_Specified(int Index) { return Fusername_Specified; } void __fastcall Setpassword(int Index, WideString _prop_val) { Fpassword = _prop_val; Fpassword_Specified = true; } bool __fastcall password_Specified(int Index) { return Fpassword_Specified; } __published: __property WideString username = { index=(IS_OPTN), read=Fusername, write=Setusername, stored = username_Specified }; __property WideString password = { index=(IS_OPTN), read=Fpassword, write=Setpassword, stored = password_Specified }; };
这里系统自动为我们生成了这个类的属性,同时我们可以了解到该类是继承自TRemotable.这是所有自定义类型会继承的基类。
__interface INTERFACE_UUID("{74DD58A1-FA8B-C1BC-7E6A-1C3F3C80D438}") NewsPublishSoap : public IInvokable { public: virtual GetAllNewsResult* GetAllNews() = 0; virtual DataInfo* GetNews(const int id) = 0; virtual int AddNews(const WideString title, const WideString content) = 0; virtual bool EditNews(const int id, const WideString title, const WideString content) = 0; virtual bool DeleteNews(const int id) = 0; virtual bool VerifyUser(const WideString username, const WideString password) = 0; virtual bool AddUser(const WideString username, const WideString password) = 0; virtual bool EditUser(const WideString username, const WideString password) = 0; virtual bool DeleteUser(const WideString username) = 0; virtual GetAllUsersResult* GetAllUsers() = 0; virtual int AddNewsAdd(const WideString title, const WideString content) = 0; virtual UserInfo* GetAUserByID(const WideString username) = 0; }; typedef DelphiInterface<NewsPublishSoap> _di_NewsPublishSoap; _di_NewsPublishSoap GetNewsPublishSoap(bool useWSDL=false, AnsiString addr="", THTTPRIO* HTTPRIO=0); }; // NS_NewsPublish