1  /  2  页   12 跳转 查看:3490

关于使用VB6通过WebService方式上传数据申请

关于使用VB6通过WebService方式上传数据申请

VB6开发环境由于不能自动生成WebService引用代理,因此使用WebService方式开发与使用XML方式开发基本类似,均需将固定格式XML文本流POST至指定服务.唯一不同是WebService方式所需XML文档遵循的是SOAP规范.
关于WebService模式所需的XML请求响应格式可参照本地服务http://127.0.0.1:9901/CertificateRequestService.asmx中的样本.如附件图所示

POST请求及解析反馈代码如下所示,以Hello World为例:

'''''''''''''''''''''''''''''''''''''''''''''''
WebServiceURL = "http://127.0.0.1:9901/CertificateRequestService.asmx"              '调用URL(URI)
WebMethodName = "http://service.vidc.info/certificaterequest/HelloWorld"            'SOAP Action
'soap请求,需要根据具体WEB SERVICES web方法更改
sentRequest="<?xml version='1.0' encoding='utf-8'?>" _
          & "<soap:Envelope xmlnssi='http://www.w3.org/2001/XMLSchema-instance' xmlnssd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"_
          & "<soap:Body>" _
          & "<HelloWorld xmlns='http://service.vidc.info/certificaterequest' />" _
          & "</soap:Body>" _
          & "</soap:Envelope>"   

'''''''''''''''''''''''''''''''''''''''''''''''
Set requestHTTP = CreateObject("Microsoft.XMLHTTP")
requestHTTP.open "POST", WebServiceURL, false
requestHTTP.setrequestheader "Content-Type", "text/xml; charset=utf-8"
requestHTTP.setrequestheader "SOAPAction", WebMethodName
requestHTTP.Send sentRequest
MsgBox("请求已经送出.  HTTP 请求处理状态= " & requestHTTP.status)

'服务反馈请求结果
MsgBox(requestHTTP.responsexml.xml)

'附加示例,处理反馈文档
Set objXml = CreateObject("MSXML2.DOMDocument")
If objXml.loadXML(requestHTTP.responseXML.xml) Then
  MsgBox(objXml.getElementsByTagName("HelloWorldResult")(0).firstChild.data)
End If 

另,部分WebMethod支持以POST方式简化调用,相关方法参考其他相关文档。

VB6开发WebService还可以采用SOAP Tools Kti开发工具包、与.Net共享程序集、通过COM或标准DLL与其他开发工具语言交互等方式实现。

附件附件:

您所在的用户组无法下载或查看附件

最后编辑00x0 最后编辑于 2009-12-22 15:59:10
 

回复:关于使用VB6通过WebService方式上传数据申请

能否给一个,上传车辆信息的例子,非常感谢
 

回复:关于使用VB6通过WebService方式上传数据申请

我不知道,车辆的各项参数都填在哪里?
 

回复:关于使用VB6通过WebService方式上传数据申请

正在了解中................
 

回复:关于使用VB6通过WebService方式上传数据申请

我是采用这种方式上传信息。但是出现一个问题。上传,修改,补传时反馈信息的NameValuePair中只有value。没有name。删除时的反馈信息是有Name 和Value的。能解答一下这是怎么回事吗?反馈信息如下。我上传了10条数据。
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlnssi="http://www.w3.org/2001/XMLSchema-instance" xmlnssd="http://www.w3.org/2001/XMLSchema"><soap:Body><UploadInsert_EntResponse xmlns="http://service.vidc.info/certificaterequest"><UploadInsert_EntResult><ResultCode xmlns="http://www.vidc.info/certificate/operation/">1</ResultCode><ResultDetail xmlns="http://www.vidc.info/certificate/operation/"><NameValuePair><Value>测试系统随机产生失败</Value></NameValuePair><NameValuePair><Value>H123456789012345678901234</Value></NameValuePair><NameValuePair><Value>H123456789012345678901234</Value></NameValuePair><NameValuePair><Value>H123456789012345678901234</Value></NameValuePair><NameValuePair><Value>H123456789012345678901234</Value></NameValuePair><NameValuePair><Value>H123456789012345678901234</Value></NameValuePair><NameValuePair><Value>H123456789012345678901234</Value></NameValuePair><NameValuePair><Value>H123456789012345678901234</Value></NameValuePair><NameValuePair><Value>测试系统随机
产生失败</Value></NameValuePair><NameValuePair><Value>测试系统随机产生失败</Value></NameValuePair></ResultDetail></UploadInsert_EntResult></UploadInsert_EntResponse></soap:Body></soap:Envelope>
 

回复: 关于使用VB6通过WebService方式上传数据申请

数据上传示例VB代码如下:

'''''''''''''''''''''''''''''''''''''''''''''''
WebServiceURL = "http://127.0.0.1:9901/CertificateRequestService.asmx"              '调用URL(URI)
WebMethodName = "http://service.vidc.info/certificaterequest/UploadInsert_Ent"      'SOAP Action
'soap请求,需要根据具体WEB SERVICES web方法更改
sentRequest="<?xml version='1.0' encoding='utf-8'?>" _
          & "<soap:Envelope xmlnssi='http://www.w3.org/2001/XMLSchema-instance' xmlnssd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" _
            & "<soap:Body>" _
              & "<UploadInsert_Ent xmlns='http://service.vidc.info/certificaterequest'>" _
                & "<data>" _
                  & "<CertificateInfo>" _
                    & "<WZHGZBH xmlns='http://www.vidc.info/certificate/operation/'>TEST99010091</WZHGZBH>" _
                    & "<CZRQ xmlns='http://www.vidc.info/certificate/operation/'>2001-12-01T12:00:00</CZRQ>" _
                  & "</CertificateInfo>" _
                  & "<CertificateInfo>" _
                    & "<WZHGZBH xmlns='http://www.vidc.info/certificate/operation/'>TEST99010092</WZHGZBH>" _
                    & "<CZRQ xmlns='http://www.vidc.info/certificate/operation/'>2001-12-01T12:00:00</CZRQ>" _
                  & "</CertificateInfo>" _
                & "</data>" _
              & "</UploadInsert_Ent>" _
            & "</soap:Body>" _
          & "</soap:Envelope>"   

'''''''''''''''''''''''''''''''''''''''''''''''
Set requestHTTP = CreateObject("Microsoft.XMLHTTP")
requestHTTP.open "POST", WebServiceURL, false
requestHTTP.setrequestheader "Content-Type", "text/xml; charset=utf-8"
requestHTTP.setrequestheader "SOAPAction", WebMethodName
requestHTTP.Send sentRequest
MsgBox("请求已经送出.  HTTP 请求处理状态= " & requestHTTP.status)

'服务反馈请求结果
MsgBox(requestHTTP.responsexml.xml)

'附加示例,处理反馈文档
ReturnCode=1
Result=""
Set objXml = CreateObject("MSXML2.DOMDocument")
If objXml.loadXML(requestHTTP.responseXML.xml) Then
  ReturnCode=objXml.getElementsByTagName("ResultCode")(0).firstChild.data
  For I=0 To (objXml.getElementsByTagName("NameValuePair").length-1)
      Name=objXml.getElementsByTagName("NameValuePair")(I).childNodes(0).text
      Value=objXml.getElementsByTagName("NameValuePair")(I).childNodes(1).text
      Result=Result+vbCrLf+Name+":"+Value
  Next
  MsgBox("操作结果:"+ReturnCode+vbCrLf+"反馈结果:"+Result)
End If 

只接收到Value属性表示合格证编号数据没能正确提交.具体错误请比对示例代码.附件为示例脚本.

附件附件:

您所在的用户组无法下载或查看附件

最后编辑00x0 最后编辑于 2009-12-22 15:59:35
 

回复: 关于使用VB6通过WebService方式上传数据申请

版主是好人,辛苦啊!不过我用的PB
 

回复: 关于使用VB6通过WebService方式上传数据申请



引用:
原帖由 EricCN 于 2009-11-16 17:23:00 发表
版主是好人,辛苦啊!不过我用的PB


PB按LZ的例子做那个也很简单的,稍微改一下就行了
 

回复:关于使用VB6通过WebService方式上传数据申请

代码好的、复杂啊
 

回复:关于使用VB6通过WebService方式上传数据申请

用这种方法上传老提示
[全项填写方式的车辆分类应该为 乘用车及客车、货车、半挂牵引车、半挂车、两轮摩托车和两轮轻便摩托车、三轮摩托车和三轮轻便摩托车、三轮汽车、低速货车、专用汽车、非《公告》车辆产品 ],[燃料种类的格式应该为 汽油 , 汽油/天然气 , 汽油/天然气/混合动力 燃料种类的取值应该为 汽油、柴油、电、混合油、天然气、液化石油气、甲醇、乙醇、太阳能、混合动力 ]

有什么解决方法


<?xml version='1.0' encoding='GB2312'?>
如果用encoding用utf-8 , xml就没法预览,肯定无法上传
最后编辑25736539 最后编辑于 2009-12-05 11:10:02
 
1  /  2  页   12 跳转

版权所有 www.vidc.info  国家机动车合格证数据中心网

Powered by Discuz!NT 2.0.1214 (Licensed)    Copyright © 2001-2012 Comsenz Inc.
Processed in 0.078125 second(s) , 6 queries. 京ICP备06025868号
返顶部