NCBI C++ ToolKit
soap_server_sample.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: soap_server_sample.cpp 90028 2020-05-05 14:02:11Z ivanov $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Andrei Gourianov
27  *
28  * File Description:
29  * Sample SOAP server
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
36 
39 
40 
41 /////////////////////////////////////////////////////////////////////////////
42 // CSampleSoapServerApplication
43 //
44 
46 {
47 public:
48  CSampleSoapServerApplication(const string& wsdl_filename, const string& namespace_name);
49  virtual void Init(void);
50  bool GetDescription(CSoapMessage& response, const CSoapMessage& request);
51  bool GetDescription2(CSoapMessage& response, const CSoapMessage& request);
52  bool GetVersion(CSoapMessage& response, const CSoapMessage& request);
53  bool DoMath(CSoapMessage& response, const CSoapMessage& request);
54 };
55 
56 
58  const string& wsdl_filename, const string& namespace_name)
59  : CSoapServerApplication(wsdl_filename,namespace_name)
60 {
61 }
62 
63 
65 {
67 
68  // Register incoming object types
69  // so the SOAP message parser can recognize these objects
70  // in incoming data and parse them correctly.
71  RegisterObjectType(CSampleVersion::GetTypeInfo);
72  RegisterObjectType(CMath::GetTypeInfo);
73 
74  // Register SOAP message processors.
75  // It is possible to set more than one listeners for a particular message.
76  // Such listeners will be called in the order of registration.
81 }
82 
83 
85  CSoapMessage& response, const CSoapMessage& request)
86 {
87  // Continue processing; call other listeners if any
88  // (Return 'false' to stop the processing)
89  return true;
90 }
91 
92 
94  CSoapMessage& response, const CSoapMessage& request)
95 {
97  resp->SetText("NCBI C++ Toolkit, Sample Soap Server Application");
98  response.AddObject(*resp,CSoapMessage::eMsgBody);
99  return true;
100 }
101 
102 
104  CSoapMessage& response, const CSoapMessage& request)
105 {
106  CConstRef<CSampleVersion> req = SOAP_GetKnownObject<CSampleVersion>(request);
108  // Just bounce ClientID
109  resp->SetVersionStruct().SetClientID(req ? req->GetClientID() : "unknown clientid");
110  resp->SetVersionStruct().SetMajor(1);
111  resp->SetVersionStruct().SetMinor(0);
112  response.AddObject(*resp,CSoapMessage::eMsgBody);
113  return true;
114 }
115 
116 
118  CSoapMessage& response, const CSoapMessage& request)
119 {
120  CConstRef<CMath> req = SOAP_GetKnownObject<CMath>(request);
122  const CMath::TOperand& ops = req->GetOperand();
123  for (const auto& op : ops) {
124  int x = op->GetX();
125  int y = op->GetY();
126  int res;
127  COperand::C_Attlist::TOperation op_type = op->GetAttlist().GetOperation();
129  res = x+y;
130  } else {
131  res = x-y;
132  }
133  resp->SetMathResult().push_back(res);
134  }
135  response.AddObject(*resp,CSoapMessage::eMsgBody);
136  return true;
137 }
138 
139 
140 /////////////////////////////////////////////////////////////////////////////
141 // MAIN
142 //
143 
144 int NcbiSys_main(int argc, ncbi::TXChar* argv[])
145 {
146  // WSDL file name is needed so the server can return it to the client upon request.
147  // In this case WSDL file should be deployed with the server.
148  //
149  // Still, it is possible to pass an empty string here -
150  // in case you do not want to disclose the WSDL specification
151 
152  return CSampleSoapServerApplication("soapserver.wsdl", "http://www.ncbi.nlm.nih.gov/").AppMain(argc, argv);
153 }
CConstRef –.
Definition: ncbiobj.hpp:1266
CDescriptionText –.
CMathResponse –.
CRef –.
Definition: ncbiobj.hpp:618
virtual void Init(void)
This method is called on the CGI application initialization – before starting to process a HTTP reque...
bool DoMath(CSoapMessage &response, const CSoapMessage &request)
bool GetDescription2(CSoapMessage &response, const CSoapMessage &request)
bool GetDescription(CSoapMessage &response, const CSoapMessage &request)
CSampleSoapServerApplication(const string &wsdl_filename, const string &namespace_name)
void AddObject(const CSerialObject &obj, EMessagePart destination)
void AddMessageListener(TWebMethod listener, const string &message_name, const string &namespace_name=kEmptyStr)
bool(CSoapServerApplication::* TWebMethod)(CSoapMessage &response, const CSoapMessage &request)
Definition: soap_server.hpp:50
void RegisterObjectType(TTypeInfoGetter type_getter)
CVersionResponse –.
int AppMain(int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
Main function (entry point) for the NCBI application.
Definition: ncbiapp.cpp:819
CVersionInfo GetVersion(void) const
Get the program version information.
Definition: ncbiapp.cpp:1184
virtual void Init(void)
This method is called on the CGI application initialization – before starting to process a HTTP reque...
Definition: cgiapp.cpp:864
char TXChar
Definition: ncbistr.hpp:172
list< CRef< COperand > > TOperand
Definition: Math_.hpp:90
EAttlist_operation TOperation
Definition: Operand_.hpp:106
USING_SCOPE(objects)
int NcbiSys_main(int argc, ncbi::TXChar *argv[])
USING_NCBI_SCOPE
Modified on Sun May 05 05:20:06 2024 by modify_doxy.py rev. 669887