zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    微博粉丝服务---“公众号”开发
    springboot --- 之SSM框架整合
    Android 接收短信
    数字币开发相关
    boot camp要求独立的fat分区
    u盘安装 osx 出现 “不能验证”
    微软驱动签名
    centos7 安装 isign
    用windbg查看dmp文件,定位bug位置
    H5移动端,ios从后台返回到app,页面会白一下
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/1332922.html
Copyright © 2011-2022 走看看