无论如何我可以打印序列化的xml消息(使用gsoap)。
例如:
soap_serialize_ns1__Response(soap, &ns2__UpdatedResponse);
我希望能够看到序列化(xml)的样子。
任何人都知道怎么做?
答案 0 :(得分:2)
无论如何我可以打印序列化的xml消息(使用gsoap)。
我希望能够看到序列化(xml)的样子。
打印"打印"对于XML中的字符串的序列化对象,您有两个选项,具体取决于您是使用C语言编写还是使用C ++编写。
在C中编码时,请执行以下操作:
var a: [(Double, Double)] = [(0.0,0.0)]
a = [(0.1234, 0.0), (0.12345, 1.0), (0.123456, 2.0), (0.1234567, 3.0)]
//the current version of the function, this is what I need to change
func getValueFromTuples(tupleArr:[(Double,Double)],n:Double)->Double?{
for tuple in tupleArr{
if tuple.0 == n{
return tuple.1
}
}
return nil
}
print("Value:", getValueFromTuples(tupleArr: a, n: 0.1234)!)
//needs to return 0.0
print("Value:", getValueFromTuples(tupleArr: a, n: 0.12345)!)
//needs to return 1.0
print("Value:", getValueFromTuples(tupleArr: a, n: 0.123456)!)
//needs to return 2.0
在C ++中编码时,请执行以下操作:
struct soap *soap = soap_new();
...
const char *str = NULL;
soap->os = &str; // assign a string to write output to
soap_write_ns1__Response(soap, &response);
soap->os = NULL; // no longer writing to the string
printf("The XML is:%s\n", str);
...
soap_end(soap); // warning: this deletes str with XML too!
str = NULL; // so make it NULL as good practice
soap_free(soap);
有关详细信息,请参阅其网站上的gSOAP XML databindgs。
答案 1 :(得分:0)
对我来说,它的工作原理如下:
int MyService::ConfirmPayment(_ns1__PaymentConfirmationRequest *ns1__PaymentConfirmationRequest, std::string &ns1__PaymentConfirmationResult) {
struct soap *soap = soap_new();
std::stringstream ss;
soap->os = &ss;
soap_write__ns1__C2BPaymentConfirmationRequest(soap, ns1__C2BPaymentConfirmationRequest);
soap->os = NULL;
std::cout << "The XML is:\n" << ss.str();
soap_destroy(soap);
soap_end(soap);
soap_free(soap);
ns1__PaymentConfirmationResult = "Transaction Queued!"
return SOAP_OK;
}