summaryrefslogtreecommitdiffstats
path: root/tags/cpp-0.1.incubating-M1-RC3/sca/samples/MyValue/Client/MyValueClient.cpp
blob: 1e5c038e2e1d9d0b5c956976c99683f0d0d5d44c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
 *
 *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
#pragma warning(disable: 4786)

#include "commonj/sdo/Logger.h"
#include "commonj/sdo/SDO.h"
#include "commonj/sdo/HelperProvider.h"
#include "osoa/sca/sca.h"
#include "tuscany/sca/util/Logger.h"
#include "tuscany/sca/util/Utils.h"
#include <iostream>

using namespace std;
using namespace osoa::sca;
using namespace tuscany::sca;
using namespace commonj::sdo;
using namespace tuscany::sca::ws;

void usage();

//
// MyValueClient is a sample application that invokes operations on the 
// MyValueService Web Service.
//
int main(int argc, char* argv[])
{

	//
	// Schema file for the types used by MyValueService
	//
	char *pszXSD;

	//
	// The WebService endpoint uri.
	//
	char *pszEndpoint;
	
	//
	// TargetNamespace
	//
	const char *pszTargetNamespace;
    
	//
	// SOAPAction
	//
	// Axis 1.5: SoapAction must be <serviceName>#<operationName>. 
	const char *pcszSoapAction = "MyValueService#getMyValue";

	//
	// Operation Name
	//
	const char *pcszOperationName = "getMyValue";

	//
	// Operation Response Name
	//
	const char *pcszOperationResponseName = "getMyValueResponse";


	// Get the input parameters.
	if (argc == 3)
	{
		// Schema file.
		pszXSD = argv[1];
		// Web Service endpoint.
		pszEndpoint = argv[2];
	}
	else
	{
		usage();
	}

	// The current version of SDO does not support the embedded schema in the wsdl file,
	// so we have to load an external schema.
	XSDHelperPtr xsdHelper = HelperProvider::getXSDHelper();

	try 
	{
		cout << "define file: " << pszXSD <<endl;
		pszTargetNamespace = xsdHelper->defineFile(pszXSD);
	}
	catch (SDORuntimeException ex)
	{
		cout << ex << endl;
		exit(1);
	}
		cout << "define file done: " << pszTargetNamespace <<endl;


	// Create an SDO for the request
	DataFactoryPtr factory = xsdHelper->getDataFactory();
    DataObjectPtr requestDO = 0;

	try 
	{
		// Create the root element for the operation and then add the parameters
		// we need to invoke the operation.
		requestDO = factory->create(pszTargetNamespace, pcszOperationName);
		requestDO->setCString("customerID", "12345");
	}
	catch (SDORuntimeException e)
	{
		cout << "SDORuntimeException: " << e << endl;
		exit(1);
	}
	
	//
	// Create an SDOStub that will use the request SDO to invoke the operation.
	//
	SDOStub *stub = new SDOStub();
	stub->setEndpoint(pszEndpoint);
	stub->setOperationName(pcszOperationName);
	stub->setTargetNamespace(pszTargetNamespace);
	stub->setOperationResponseName(pcszOperationResponseName);
	stub->setSoapAction(pcszSoapAction);
	// DEBUG - Don't let the soap transport timeout while debugging.
	stub->setTransportTimeout(0);
	// DEBUG
			
	try 
	{
        // Invoke the operation.
    	DataObjectPtr responseDO = stub->invoke(requestDO, factory);
		// Print the response.
		if (responseDO != 0)
		{
			cout << "MyValueClient: response DataObject = " << endl;
			Utils::printDO(responseDO);
			cout << endl;
			float fValue = responseDO->getFloat("myValue");
			cout << "MyValueClient: myValue = " << fValue;
		}
		else
		{
			cout << "MyValueClient: MyValueService did not return a result" << endl;
		}
	} 
	catch (SDORuntimeException& e)
	{
		cout << "SDORuntimeException: " << e << endl;
	}
	catch (ServiceRuntimeException& e)
	{
		cout << "ServiceRuntimeException: " << e << endl;
	}
	catch(exception& e)
	{
		cout << "Exception: " << e.what() << endl;
	}
	

	return 0;
}

//
// Print usage message.
//
void usage()
{
	cout << "MyValueClient.exe: Invoke operations on MyValueService Web Service" << endl;
	cout << "Usage: MyValueClient XSD endpoint" << endl;
	cout << "where  XSD = path and name of XSD file that defines the MyValue types" << endl;
	cout << "       endpoint = web service endpoint" << endl;
	exit(1);
}