2017-02-17 59 views
0

无论如何,我可以打印序列化的XML消息(使用gsoap)。gSOAP序列化XML到字符串

例如:

soap_serialize_ns1__Response(soap, &ns2__UpdatedResponse); 

我希望能够看到什么序列化(XML)的模样。

任何人都知道如何?

回答

1

无论如何,我可以打印序列化的xml消息(使用gsoap)。

我希望能够看到序列化(xml)的样子。

要将序列化对象“打印”为XML格式的字符串,有两种选择,具体取决于您使用的是C语言还是C++语言。

当用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); 

当用C++编码做到以下几点:

soap *soap = soap_new(); 
... 
std::stringstream ss; 
soap->os = &ss; // assign a stringstream to write output to 
soap_write_ns1__Response(soap, &response); 
soap->os = NULL; // no longer writing to the stream 
std::cout << "The XML is:\n" << ss.str(); 
... 
soap_destroy(soap); 
soap_end(soap); 
soap_free(soap); 

gSOAP XML databindgs在他们的网站了解详情。

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; 
}