Delphi/BCB下 Webservice client编程
8 月.24, 2015 in
编程小记
又开始倒腾webservice了,习惯性使用bcb6来弄,遇到了些问题,在这里记录一下:
1)按照其它文章描述的那样,需要考虑处理中文,增加UTF8相应设置,这里需要提示下部分主机会需要认证,处理的位置在rio->HTTPWebNode->UserName处:
_di_SamServicePortType GetSamServicePortType(AnsiString username, AnsiString passwd, bool useWSDL, AnsiString addr) { static const char* defWSDL= "C:\Documents and Settings\Administrator\My Documents\samapi.xml"; static const char* defURL = "http://192.168.13.19:8080/sam/services/samapi"; static const char* defSvc = "SamService"; static const char* defPrt = "SamServicePort"; 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; } rio->HTTPWebNode->UseUTF8InHeader = true; if(!(username=="" && passwd=="")) { rio->HTTPWebNode->UserName = username; rio->HTTPWebNode->Password = passwd; } rio->Converter->Options<<soUTF8InHeader; _di_SamServicePortType service; rio->QueryInterface(service); if (!service) delete rio; return service; } |
2)设置RegTypes
大部分文章提到要设置RegisterInvokeOptions,修改为ioDocument,这样是不够的,应该如下:
static void RegTypes() { /* SamServicePortType */ InvRegistry()->RegisterInterface(__interfaceTypeinfo(SamServicePortType), L"http://api.spl.ruijie.com/", L"UTF-8"); InvRegistry()->RegisterDefaultSOAPAction(__interfaceTypeinfo(SamServicePortType), L""); InvRegistry()->RegisterInvokeOptions(__interfaceTypeinfo(SamServicePortType), ioDocument|ioLiteral|ioHasNamespace); } |
如果不设置ioHasNamespace,在上传参数时可能会出现提示参数不可为空,“Unmarshalling Error”之类的错误。
Leave a Reply
You must be logged in to post a comment.