2017-02-17 75 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; 
}