I have implemented a service in C++ using gSoap. I have created it from a multiple existing WSDL files.
And now I need to give a definition to every virtual method of the service.
Let's take a look at one generated method declaration in the file soapMyServiceService.h:
///
/// Service operations (you should define these):
/// Note: compile with -DWITH_PURE_VIRTUAL for pure virtual methods
///
/// Web service operation 'Initialize' (returns error code or SOAP_OK)
virtual int Initialize(_ns5__Initialize *ns5__Initialize, _ns5__InitializeResponse *ns5__InitializeResponse);
Actually, I was expecting to get :
virtial string Initialize(int var_a , int var_b , string var_c);
But now, I need to implement it what I got generated and return the SOAP code :
int MyService::Initialize(_ns5__Initialize *ns5__Initialize, _ns5__InitializeResponse *ns5__InitializeResponse)
{
// HOW can I get here the received values for that I can able to implement my logic?
return SOAP_OK;
}
How can I get the received values ( the values sent by the client for var_a, var_b, and var_c) and then set for him the returned for the string and in the same time return the error code...
How do you normally implement the logic of the services?
Thank you.
In your service method implementation MyService::Initialize(_ns5__Initialize *ns5__Initialize, _ns5__InitializeResponse *ns5__InitializeResponse)
the last argument is the response argument all the rest are input argument, here you have only one input parameter that is of type _ns5__Initialize which probably wud be a structure, if you access its member, you will get all the input parameters of the request.
Related
I have started using XML-RPC for C/C++ (Xmlrpc-c) library on an embedded device, to implement a simple client application.
I need to use xmlrpc_c::clientSimple class to setup a request message as follows:
xmlrpc_c::paramList getParams;
getParams.add("userName");
getParams.add("password");
xmlrpc_c::clientSimple myClient;
xmlrpc_c::value result;
myClient.call("serverUrl", "verifyAccount", tokenGetParams, &result);
I see there are utilities to get int, string (etc.) values from result variable:
xmlrpc_c::value_string(result);
xmlrpc_c::value_int(result);
...
What if I get a more than a variable as result of my RPC call?
For example if the result is made up of an int value and a string, should I convert xmlrpc_c::value to a struct?
What is the best way to do that?
I am using boost test within a home-grown GUI, and want to access test results (e.g. the failure message and location when a test fails)
The unit_test::test_observer class provides the virtual method:
void assertion_result(boost::unit_test::assertion_result)
However, unit_test::assertion_result is just an enum indicating success or failure. From there, I cannot see how to access further information about the test result.
The framework also provides the class test_tools::assertion_result, which encapsulates an error message, but this only appears to be used for evaluating pre-conditions. (I would have expected this type to be the argument to unit_test::test_observer::assertion_result).
The log output classes appear to provide more information on test results. These are implemented as streams, which makes it non-trivial to extract test result data.
Does anyone know how I can access the information on test results - success/failure, the test code, the location, etc?
Adding an observer will not give you the level of details you need.
From this class you can add your own formatter using the add_formatter function. This will contain the details of what is happening and where, depending on the formatter log level.
I am trying to initialize a server to look as specific inputs based on the request it gets. there are a lot of them so I want to initialize it with a loop as follows:
void serverInit() {
for (int i = 1; i <= qty; i++) {
String s = "/readBatt" + i;
server.on(s, runTest(i));
}
server.begin();
Serial.println("Server started.");
}
It's telling me that server.on(s, runTest(i)); is an invalid use of void expression. I know it wants it formatted as server.on(s, runTest) but the function runTest(int n) takes a parameter. How can i pass this parameter through to the function?
It seems you are using the WebServer class from the ESP32 Arduino libraries. As you have gleaned already, the callback specified in the on() method does not accept any arguments.
You have an alternative, however. You can specify a 'placeholder' in the URL path - using curly brackets - {}. In the callback, then, the corresponding argument can be retrieved by using the pathArg() method - which accepts the argument index as parameter.
Example ...
You could define your API endpoint as /readBatt/<battery number>. To configure the server to handle requests to this endpoint, then, you would use something like
#include <uri/UriBraces.h>
server.on(UriBraces("/readBatt/{}"), runTest);
In your callback, you would retrieve the first argument as follows ...
static void runTest() {
String batteryNumber = server.pathArg(0);
Serial.println("Request to read battery");
String response = "You attempted to read battery " + batteryNumber;
response += ".\nThis endpoint is a placeholder. Check again soon!";
server.send(200, "text/plain", response);
}
Finally ... Suppose your ESP8266 was running on local IP address 192.168.1.9. You could access your new API endpoint by opening
http://192.168.1.9/readBatt/1
in your browser. (Replace 1 with the relevant battery number.)
I don't think there are versions of the pathArg() which return an integer, unfortunately, so you may have to perform a conversion at some point.
You can use what's called a "closure". A closure lets you compose a function which retains access to variables outside of its scope.
A closure is written using a "lambda expression" - basically an anonymous function. C++'s syntax for lambda expressions looks like this:
[capture variable list](argument list) { body}
The capture variable list is a list of variables you want to be made available inside the body. The argument list is the normal function argument list that would get passed in by the caller. You'd write the lambda expression you need like this:
[i]() { runTest(i); }
and use it like this:
server.on(s, [i]() { runTest(i); });
To be clear, #David Collins' answer is the better way to write the web server. Using a parameter in the URL is better than creating several URLs with the parameter embedded in them. I'm just answering the question of how to pass a parameter to a function that gets called without arguments. If you write the web server code the better way, you won't need to do this (although I would do a bounds check on the value passed in the URL to make sure you're getting a valid battery number).
I have a method with input param as Array. When I generate stub out of it creates List type.
But I want to know how to create a wrapper class around array type e.g. for class Apple it should create ArrayOfApple.
Is there any change needs to be done in class or any specific plugin need to be used?
Note: I am using JAXWS with Apache CXF implementation
Below is the sample code:
EmployeeService.java:
#WebService(endpointInterface="com.test.EmployeeService")
#SOAPBinding(style=Style.DOCUMENT)
public class EmployeeService {
public String updateEmpRoles(#WebParam(name="EmpRoles")EmpRole[] empRoles) {
return "SUCCESS";
}
}
EmpRole.java :
#XmlType(name="EmpRole")
public class EmpRole {
private String empRole;
public String getEmpRole() {
return empRole;
}
public void setEmpRole(String empRole) {
this.empRole = empRole;
}
}
After publishing, wsdl is getting generated as below -
But what I expect is WSDL should create ArrayOfEmpRole and it should wrap List<EmpRole>.
Kindly help
In short - I want something that Björn doesn't want in below link. (In his case, it's automatically creating ArrayOfXXX, this is what I need) - Arrays in SOAP method Parameters generated via JAX-WS?
I would switch from Code first to a Contract first approach which means start with the WSDL and generate a stub using wsdl2java from it. This way you can ensure that the WSDL looks like the way you want.
If you want to stick to the current approach, the easiest way to achieve a wrapper is probably to introduce another class.
I am trying to expose a C++ library to python using boost-python. The library actually wraps an underlying C api, so uses raw pointers a lot.
// implementation of function that creates a Request object
inline Request Service::createRequest(const char* operation) const
{
blpapi_Request_t *request;
ExceptionUtil::throwOnError(
blpapi_Service_createRequest(d_handle, &request, operation)
);
return Request(request);
}
// request.h
class Request {
blpapi_Request_t *d_handle;
Element d_elements;
Request& operator=(const Request& rhs); // not implemented
public:
explicit Request(blpapi_Request_t *handle);
Request(RequestRef ref);
Request(Request &src);
};
// request.cpp
BOOST_PYTHON_MODULE(request)
{
class_<blpapi_Request_t>;
class_<Request, boost::noncopyable>("Request", init<blpapi_Request_t *>())
.def(init<Request&>())
;
}
Although request.cpp compiles successfully, when I try and use the object I get the following error:
// error output
TypeError: No to_python (by-value) converter found for C++ type: class Request
In-order to call this the python code looks like:
from session import *
from service import *
from request import *
so = SessionOptions()
so.setServerHost('localhost')
so.setServerPort(8194)
session = Session(so)
# start sesssion
if not session.start():
print 'Failed to start session'
raise Exception
if not session.openService('//blp/refdata'):
print 'Failed to open service //blp/refdata'
raise Exception
service = session.getService('//blp/refdata')
request = service.createRequest('ReferenceDataRequest')
The other objects (SessionOptions, Session, Service) etc are also c++ objects that I have successfully created boost-python wrappers for.
As I understand from the boost-python docs this has something to do with passing a raw pointer around, but I don't really understand what else I should do ...
Your class_<blpapi_Request_t>; does not declare anything; is that code the correct version?
If so, then update it:
class_<blpapi_Request_t>("blpapi_Request_t");
That said, what that error indicates is that you are trying to use the Request object with an automatic conversion to a python object which has not been defined.
The reason you get this error is because you have wrapped Request as boost::noncopyable, then provided a factory method which returns a Request object by value; the boost::noncopyable means no copy constructors are generated and therefore there's no automatic to-python converter.
Two ways out of this: one is to remove the noncopyable hint; the other would be to register a converter which takes a C++ Request and returns a Python Request object. Do you really need the noncopyable semantics for Request?