C++ Builderを使用して「Hello World」の例を作成しようとしています。これは私の最初のプロジェクトですので、おそらく簡単な間違いをしました。webservice(hello world)を呼び出すC++ Builderコンソールアプリケーション
電卓のWebサービスを呼び出すコンソールアプリケーションを作成します。
C++ Builder 2007を開き、コンソールアプリケーションを作成します。 File1.cppというcppファイルが表示されます。ここでは、コンテンツです:
//---------------------------------------------------------------------------
#include <iostream.h>
#include <vcl.h>
#pragma hdrstop
#include "calculator.h"
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
double a, b;
cout << "Enter the values to sum\n";
cout << "A: ";
cin >> a;
cout << "B: ";
cin >> b;
cout << "\nA+B:";
cout << GetCalculatorSoap()->Add(1,2);
cout << "\n\nPress any key to continue...";
getchar();
return 0;
}
//---------------------------------------------------------------------------
さらに私は、新規作成 - >その他 - > WebService-> WSDLインポータに入るSOAPプロキシを追加しました。 WSDLにhttp://www.dneonline.com/calculator.asmx?WSDL
を使用してこのアクションは、calculator.cppを追加しました:
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://www.dneonline.com/calculator.asmx?WSDL
// >Import : http://www.dneonline.com/calculator.asmx?WSDL:0
// Encoding : utf-8
// Version : 1.0
// (21/02/2012 19:48:31 - - $Rev: 10138 $)
// ************************************************************************ //
#include <vcl.h>
#pragma hdrstop
#if !defined(calculatorH)
#include "calculator.h"
#endif
namespace NS_calculator {
_di_CalculatorSoap GetCalculatorSoap(bool useWSDL,
AnsiString addr, THTTPRIO* HTTPRIO)
{
static const char* defWSDL= "http://www.dneonline.com/calculator.asmx?WSDL";
static const char* defURL = "http://www.dneonline.com/calculator.asmx";
static const char* defSvc = "Calculator";
static const char* defPrt = "CalculatorSoap";
if (addr=="")
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_CalculatorSoap 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()
{
/* CalculatorSoap */
InvRegistry()->RegisterInterface(__interfaceTypeinfo(CalculatorSoap),
L"http://tempuri.org/", L"utf-8");
InvRegistry()->RegisterDefaultSOAPAction(__interfaceTypeinfo(CalculatorSoap),
L"http://tempuri.org/%operationName%");
InvRegistry()->RegisterInvokeOptions(__interfaceTypeinfo(CalculatorSoap),
ioDocument);
}
#pragma startup RegTypes 32
}; // NS_calculator
私はアプリケーションを実行するとGetCalculatorSoapを呼び出すときに例外を発生させます() - >(1,2)を追加します。
---------------------------
Debugger Exception Notification
---------------------------
Project Test.exe raised exception class EOleSysError
with message 'CoInitialize has not been called'.
---------------------------
Break Continue Help
---------------------------
デバッグすると、GetCalculatorSoap()は正常に実行されますが、Addメソッドを呼び出す直前に例外がスローされます。
どんなアイデアが間違っている?ありがとう!
ありがとうございました。低レベルのスタッフがたくさんいます... – Eduard
SOAPコードのどの部分にCOMが必要ですか?HTTPRIOにはCOMが動作する必要がありますか? – Eduard
私はそれを考えています。ソースを確認することができますが、それが使用するユニットとそれがベースにしているインタフェースで分かります。コンソールアプリケーションコードには何も表示されませんしかし、私はそれがCOMを使用していることを示すSOAPコード内の 'QueryInterface'への呼び出しを見ています。 –