• C++ Builder调用C#的Webservice


    1、导入的Service.cpp
    // ************************************************************************ //
    // The types declared in this file were generated from data read from the
    // WSDL File described below:
    // WSDL     : http://localhost:1043/Web/Service.asmx?wsdl
    //  >Import : http://localhost:1043/Web/Service.asmx?wsdl:0
    // Encoding : utf-8
    // Version  : 1.0
    // (2008-2-19 21:50:12 - - $Rev: 7010 $)
    // ************************************************************************ //

    #include <vcl.h>
    #pragma hdrstop

    #if !defined(ServiceH)
    #include "Service.h"
    #endif

    namespace NS_Service {

    _di_ServiceSoap GetServiceSoap(bool useWSDL, AnsiString addr, THTTPRIO* HTTPRIO)
    {
      static const char* defWSDL= "http://localhost:1043/Web/Service.asmx?wsdl";
      static const char* defURL = "http://localhost:1043/Web/Service.asmx";
      static const char* defSvc = "Service";
      static const char* defPrt = "ServiceSoap";
      if (addr=="http://www.blog.com.cn/")
        addr = useWSDL ? defWSDL : defURL;
      THTTPRIO* rio = HTTPRIO ? HTTPRIO : new THTTPRIO(0);
      if (useWSDL) {
        rio->WSDLLocation = addr;
        rio->Service = defSvc;
        rio->Port = defPrt;
      } else {
        rio->URL = addr;
      }
      _di_ServiceSoap service;
      rio->QueryInterface(service);
      if (!service && !HTTPRIO)
        delete rio;
      return service;
    }

    // ************************************************************************ //
    // This routine registers the interfaces and types exposed by the WebService.
    // ************************************************************************ //
    static void RegTypes()
    {
      /* ServiceSoap */
      InvRegistry()->RegisterInterface(__interfaceTypeinfo(ServiceSoap), L"http://tempuri.org/", L"utf-8");
      InvRegistry()->RegisterDefaultSOAPAction(__interfaceTypeinfo(ServiceSoap), L"http://tempuri.org/%operationName%");
      InvRegistry()->RegisterInvokeOptions(__interfaceTypeinfo(ServiceSoap), ioDocument);
    }
    #pragma startup RegTypes 32

    };     // NS_Service

    ===================================================
    2、Service.h
    // ************************************************************************ //
    // The types declared in this file were generated from data read from the
    // WSDL File described below:
    // WSDL     : http://localhost:1043/Web/Service.asmx?wsdl
    //  >Import : http://localhost:1043/Web/Service.asmx?wsdl:0
    // Encoding : utf-8
    // Version  : 1.0
    // (2008-2-19 21:50:12 - - $Rev: 7010 $)
    // ************************************************************************ //

    #ifndef   ServiceH
    #define   ServiceH

    #include <System.hpp>
    #include <InvokeRegistry.hpp>
    #include <XSBuiltIns.hpp>
    #include <SOAPHTTPClient.hpp>

    #if !defined(SOAP_REMOTABLE_CLASS)
    #define SOAP_REMOTABLE_CLASS __declspec(delphiclass)
    #endif
    #if !defined(IS_OPTN)
    #define IS_OPTN 0x0001
    #endif

    namespace NS_Service {

    // ************************************************************************ //
    // The following types, referred to in the WSDL document are not being represented
    // in this file. They are either aliases[@] of other types represented or were referred
    // to but never[!] declared in the document. The types from the latter category
    // typically map to predefined/known XML or Borland types; however, they could also
    // indicate incorrect WSDL documents that failed to declare or import a schema type.
    // ************************************************************************ //
    // !:string          - "http://www.w3.org/2001/XMLSchema"

    // ************************************************************************ //
    // Namespace : http://tempuri.org/
    // soapAction: http://tempuri.org/%operationName%
    // transport : http://schemas.xmlsoap.org/soap/http
    // style     : document
    // binding   : ServiceSoap
    // service   : Service
    // port      : ServiceSoap
    // URL       : http://localhost:1043/Web/Service.asmx
    // ************************************************************************ //
    __interface INTERFACE_UUID("{77573149-9C57-FA51-F11F-EFD527C91BD9}") ServiceSoap : public IInvokable
    {
    public:
      virtual WideString      Test() = 0;
      virtual WideString      Test2(const WideString s) = 0;
    };
    typedef DelphiInterface<ServiceSoap> _di_ServiceSoap;

    _di_ServiceSoap GetServiceSoap(bool useWSDL=false, AnsiString addr="", THTTPRIO* HTTPRIO=0);

    };     // NS_Service

    #if !defined(NO_IMPLICIT_NAMESPACE_USE)
    using  namespace NS_Service;
    #endif

    #endif // ServiceH
    ===========================================================
    3、调用代码
    NS_Service::_di_ServiceSoap p = NS_Service::GetServiceSoap(true, "", NULL);
        WideString s = "ok";
    WideString str = p->Test2(s);
    p->Test();
    MessageBoxW(NULL, str.c_bstr(), NULL, MB_OK);

  • 相关阅读:
    小笔记——a标签触发file
    错误笔记——MVC自带验证
    错误笔记——表达式树不能包含动态操作(aspx)的解决
    囫囵吞枣——Bootstrap
    闪回技术
    RAC架构中各种日志所在路径
    行迁移与行链接
    BBED制作空块并用rman恢复(修改坏块前一定要做rman备份!!!)
    死锁处理
    更改一字段的全部字节的大小写
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/1332922.html
Copyright © 2020-2023  润新知