Rework the parsing of soap response.
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
|
||||
#include "example/common/book_xml.h"
|
||||
|
||||
static const std::string kResultName = "Result";
|
||||
|
||||
static void PrintSeparateLine() {
|
||||
std::cout << "--------------------------------";
|
||||
std::cout << "--------------------------------";
|
||||
@@ -16,7 +18,6 @@ BookClient::BookClient(const std::string& host, const std::string& port)
|
||||
: soap_client_(host, port), code_(0) {
|
||||
soap_client_.set_url("/book");
|
||||
soap_client_.set_service_ns({ "ser", "http://www.example.com/book/" });
|
||||
soap_client_.set_result_name("Result");
|
||||
|
||||
// Customize response XML format.
|
||||
soap_client_.set_format_raw(false);
|
||||
@@ -91,7 +92,6 @@ bool BookClient::Call0(const std::string& operation, std::string* result_str) {
|
||||
return Call(operation, {}, result_str);
|
||||
}
|
||||
|
||||
|
||||
bool BookClient::Call1(const std::string& operation,
|
||||
webcc::SoapParameter&& parameter,
|
||||
std::string* result_str) {
|
||||
@@ -104,7 +104,8 @@ bool BookClient::Call1(const std::string& operation,
|
||||
bool BookClient::Call(const std::string& operation,
|
||||
std::vector<webcc::SoapParameter>&& parameters,
|
||||
std::string* result_str) {
|
||||
if (!soap_client_.Request(operation, std::move(parameters), result_str)) {
|
||||
if (!soap_client_.Request(operation, std::move(parameters), kResultName,
|
||||
result_str)) {
|
||||
PrintError();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ bool BookService::CreateBook(const webcc::SoapRequest& soap_request,
|
||||
std::string id = g_book_store.AddBook(book);
|
||||
|
||||
std::string response_xml = NewResultXml(0, "ok", "book", "id",
|
||||
id.c_str());
|
||||
id.c_str());
|
||||
|
||||
soap_response->set_result_moved(std::move(response_xml), true);
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static const std::string kResultName = "Result";
|
||||
|
||||
class CalcClient {
|
||||
public:
|
||||
CalcClient(const std::string& host, const std::string& port)
|
||||
@@ -15,7 +17,6 @@ class CalcClient {
|
||||
soap_client_.set_service_ns({
|
||||
"ser", "http://www.example.com/calculator/"
|
||||
});
|
||||
soap_client_.set_result_name("Result");
|
||||
|
||||
// Customize request XML format.
|
||||
soap_client_.set_format_raw(false);
|
||||
@@ -54,7 +55,8 @@ class CalcClient {
|
||||
};
|
||||
|
||||
std::string result_str;
|
||||
if (!soap_client_.Request(operation, std::move(parameters), &result_str)) {
|
||||
if (!soap_client_.Request(operation, std::move(parameters), kResultName,
|
||||
&result_str)) {
|
||||
PrintError();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static const std::string kResultName = "Result";
|
||||
|
||||
class CalcClient {
|
||||
public:
|
||||
// NOTE: Parasoft's calculator service uses SOAP V1.1.
|
||||
@@ -16,7 +18,6 @@ class CalcClient {
|
||||
soap_client_.set_service_ns({
|
||||
"cal", "http://www.parasoft.com/wsdl/calculator/"
|
||||
});
|
||||
soap_client_.set_result_name("Result");
|
||||
|
||||
// Customize request XML format.
|
||||
soap_client_.set_format_raw(false);
|
||||
@@ -39,6 +40,11 @@ class CalcClient {
|
||||
return Calc("divide", "numerator", "denominator", x, y, result);
|
||||
}
|
||||
|
||||
// Only for testing purpose.
|
||||
bool Unknown(double x, double y, double* result) {
|
||||
return Calc("unknown", "x", "y", x, y, result);
|
||||
}
|
||||
|
||||
private:
|
||||
bool Calc(const std::string& operation,
|
||||
const std::string& x_name, const std::string& y_name,
|
||||
@@ -50,7 +56,8 @@ class CalcClient {
|
||||
};
|
||||
|
||||
std::string result_str;
|
||||
if (!soap_client_.Request(operation, std::move(parameters), &result_str)) {
|
||||
if (!soap_client_.Request(operation, std::move(parameters), kResultName,
|
||||
&result_str)) {
|
||||
PrintError();
|
||||
return false;
|
||||
}
|
||||
@@ -69,7 +76,12 @@ class CalcClient {
|
||||
if (soap_client_.timed_out()) {
|
||||
std::cout << " (timed out)";
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
if (soap_client_.fault()) {
|
||||
std::cout << *soap_client_.fault() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
webcc::SoapClient soap_client_;
|
||||
@@ -102,5 +114,7 @@ int main() {
|
||||
printf("divide: %.1f\n", result);
|
||||
}
|
||||
|
||||
calc.Unknown(x, y, &result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user