VS 2008 mfc 智能应用程序 调用 C# webservice.(二),gsoap+wince

在桌面窗体应用程序 ,服务调用成功 ,上传文件成功了,本以为WM中也是一样啊 依葫芦画瓢,靠,没想到啊。。。。。。。。。。。。

项目->属性->常规->公共语言库支持,靠 没有这一选项。。。难道不能调用服务了在MFC native c++ 中?怎么办 怎么办 怎么 办 ?慌了

网上看了 用gsoap gsoap?什么东西啊 ,没见过,又折腾了好久

1 Gsoap 使用

  1. 下载gsoap (gsoap-2.8)(版本 for CE DVICE改进版)址(:http://sourceforge.net/projects/gsoap2/)
  2. 解压(E:\Development\cpp\gsoap-2.8)
  3. 打开“命令提示符”(开始-附件)(又没用过的东东......)

3.1 定位到目录(E:\Development\cpp\gsoap-2.8\gsoap\bin\win32)(命令 e: 回车;cd E:\Development\cpp\gsoap-2.8\gsoap\bin\win32)

4. 命令: wsdl2h -s -0 testhello.h htttp://192.169.0.110/MobileService/Service.asmx?wsdl

在win32 文件夹下 生成testhello.h

5.命令 : soapcpp2.exe -C testhello.h

生成一大推文件,其中有用的文件 (soapH.h ; soapStub.h ; soapC.cpp ; soapClient.cpp ;ServiceSoap.namap; stdsoap2.h;stdsoap2.cpp);其中 stdsoap2.h;stdsoap2.cpp 在gsoap 文件夹下

6. 将上面文件复制到 MW 工程目录下

ok 回到WM 工程中

#include "soapH.h"

#include "ServiceSoap.nsmap"

 struct soap clientSOAP;

       struct _ns1__sayHello sayHelloMsg;

       struct _ns1__sayHelloResponse sayHelloResponse;


       soap_init(&clientSOAP);

            CString  tmp1=_T("yandy");

           DWORD dwNum ;
           dwNum= WideCharToMultiByte(CP_OEMCP, NULL, tmp1.GetBuffer(0), -1, NULL, 0, NULL, FALSE);
             char *psText;
             psText = new char[dwNum];
             if (!psText)
                 delete []psText;
            WideCharToMultiByte(CP_OEMCP, NULL, tmp1.GetBuffer(0), -1, psText, dwNum, NULL, FALSE);


     sayHelloMsg.name = psText;


       if(soap_call___ns2__sayHello(&clientSOAP, NULL, NULL, &sayHelloMsg, &sayHelloResponse) == SOAP_OK)

       {

              //printf("%s\n", *sayHelloResponse.return_);

            //  cout<<*(sayHelloResponse.return_)<<endl;

                   char *result;
                   result=new char[100];
                 result=  sayHelloResponse.sayHelloResult;

                 TCHAR Name[100];

        MultiByteToWideChar(CP_ACP, 0, result, -1, Name, 100);


                          TRACE(_T("good!"));
                          TRACE(Name);
                          TRACE(_T("good!"));

       }

       else

       {

              TRACE(_T("Error\n"));

       }


       delete sayHelloMsg.name;

       soap_destroy(&clientSOAP);

       soap_end(&clientSOAP);

       soap_done(&clientSOAP);


输出 hellowordyandy

如果要上传文件 必须 对 xsd__base64Binary 进行初始化,把读取文件的char[] 传递给 xsd__base64Binary

    struct soap clientSOAP;
         struct xsd__base64Binary ret;
        soap_init(&clientSOAP);
        //  soap_malloc(clientSOAP,flen+10);
         ret.__ptr=(unsigned char *)soap_malloc(&clientSOAP,flen);
         ret.__size=flen;
         memset(ret.__ptr,0,flen);
         memcpy(ret.__ptr,p,flen);
    struct  _ns1__uplowadfile  uplowadfile;
        struct  _ns1__uplowadfileResponse uplowadfileResponse;

终于告一段落,你妈 伤不起。。。。。。。不知道 在真机上用GPRS 还是不是有啥问题