C++调用WebService
作者:网络转载 发布时间:[ 2014/9/18 13:12:37 ] 推荐标签:软件开发 Net
5. 使用的例子:
1 CString CGetLocation::GetLocation(int iLon, int iLat)
2 {
3 CString strAddress = _T("");
4
5 struct soap soap1 ;
6 soap_init(&soap1);
7 soap_set_mode(&soap1, SOAP_C_MBSTRING);
8
9 BasicHttpBinding_USCOREIGMMProxy locationService(soap1);
10
11 _ns3__GetLocation getLocation;
12 _ns3__GetLocationResponse getLocationRes;
13
14 bool blOffset = false;
15 getLocation.Latitude = &iLat;
16 getLocation.Longitude = &iLon;
17 getLocation.blOffset = &blOffset;
18
19 int nOK = -1;
20
21 try
22 {
23 nOK = locationService.GetLocation(strWCFUrl.c_str(), NULL, &getLocation, &getLocationRes);
24 }
25 catch (...)
26 {
27 CString strLog;
28 strLog.Format(_T("GetLocation try catch error : %d "), GetLastError());
29 TRACE(strLog);
30 return strAddress;
31 }
32
33
34 if (nOK != SOAP_OK)
35 {
36 char szError[255] = {0};
37 soap_sprint_fault(&soap1, szError, 255);
38
39 CString strLog;
40 strLog.Format(_T("SOAP Error: %s "), szError);
41 TRACE(strLog);
42 return strAddress;
43 }
44
45 if (getLocationRes.GetLocationResult == NULL || (*getLocationRes.GetLocationResult).empty())
46 {
47 CString strLog;
48 strLog.Format(_T("SOAP Result: Error "));
49 TRACE(strLog);
50 return strAddress;
51 }
52
53 strAddress = (*getLocationRes.GetLocationResult).c_str();
54 return strAddress;
55 }
本文内容不用于商业目的,如涉及知识产权问题,请权利人联系SPASVO小编(021-61079698-8054),我们将立即处理,马上删除。

sales@spasvo.com