How does the atlserver WebService return soap messages of arbitrary content to customers? -- rewrite atlsoap. h

Source: Internet
Author: User

How does the atlserver WebService return soap messages of arbitrary content to the customer?

Cheungmine@gmail.com

2007-3-24

(The previous article has a problem. Here is the available version .)

To return any soap error message to the customer in the following WebService method:

// Macro definition. The error message is only half-width English
# DefineSoap_fault(Errcode, wszdetail)M_fault. M_soaperrcode = errcode;M_fault. M_strdetail = wszdetail

[Soap_method] hresult helloworld (/* [in] */BSTR bstrinput,/* [out, retval] */BSTR * bstroutput) {ccombstr bstrout (L "hello "); bstrout + = bstrinput; * bstroutput = bstrout. detach (); Soap_fault ( Soap_e_server, l "Do you love me, my girl ");Return e_fail;} however, M_faultThe parameter is undefined. We need to add it to the atlsoap. h file. Open atlsoap. h and add the following code. Note that the red part is added. Do not change it elsewhere:

Template <typename thandler>
Class csoaphandler:
Public csoaproothandler,
Public ccomobjectrootex <ccommultithreadmodel>,
Public irequesthandlerimpl <thandler>
{
Protected:
Http_code m_hcerr;
Chttpresponse * m_phttpresponse;

// Heap for SOAP requests
Cwin32heap m_heap;

// Default heap is com heap (soap servers can double as COM objects)
Ccomheap m_comheap;

 // Cl2: Add a member to return custom errors instead of generating Errors Based on the hresult value.
Csoapfault m_fault;
Public:

Begin_com_map (csoaphandler <thandler>)
Com_interface_entry (isaxcontenthandler)
Com_interface_entry (irequesthandler)
End_com_map ()

Csoaphandler ()
: M_phttpresponse (null), m_hcerr (http_success)
{
Setmemmgr (& m_comheap );
}

Void sethttperror (http_code hcerr)
{
M_hcerr = hcerr;
}

Hresult soapfault (
Soap_error_code errcode,
Const wchar_t * wszdetail,
Int cchdetail)
{
Atlassume (m_phttpresponse! = NULL );

Sethttperror (atlshttperror (500, suberr_no_process ));

M_phttpresponse-> clearheaders ();
M_phttpresponse-> clearcontent ();
M_phttpresponse-> setcontenttype ("text/XML ");
M_phttpresponse-> setstatuscode (500 );

 If (m_fault.m_soaperrcode =Soap_e_unk)
{
If (wszdetail! = NULL)
{
If (cchdetail <0)
{
Cchdetail = (INT) wcslen (wszdetail );
}

_ Atltry
{
M_fault. M_strdetail.setstring (wszdetail, cchdetail );
}
_ Atlcatchall ()
{
Atltrace (_ T ("csoaphandler: soapfault -- out of memory ."));

Return e_outofmemory;
}
}

M_fault. M_soaperrcode = errcode;
}

M_fault. Generatefault (m_phttpresponse );

Return s_ OK;
}......

The preceding figure shows the returned error message "<detail>Do you love me, my girl</Detail> ". I use vs2005 + atl8 to write WebService. WebService written in other languages does not know these problems. If you want to make good use of the ATL server, it is normal to make some modifications to its code. I modified many of its default implementations, such as csessionstateservice and cperfmon.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.