Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I need to get body tags of incoming request to my WCF service. But i am getting as STREAM.

C#
public string GetCountryDetails(string xmlstring)
{
	try
	{
		string bodyxml = OperationContext.Current.RequestContext.RequestMessage.Tostring();
	}
	catch(Exception ex)
	{

	}
}


What I have tried:

public string GetCountryDetails(string xmlstring)
{
try
{
string bodyxml = OperationContext.Current.RequestContext.RequestMessage.Tostring();
}
catch(Exception ex)
{

}
}

O/p:-
XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header>
    <To soapenv:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://localhost:51047/Service1.svc</To>
    <Action soapenv:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">urn:IService1/GET_COUNTRY_DETAILS</Action>
  </soapenv:Header>
  <soapenv:Body>... stream ...</soapenv:Body>
</soapenv:Envelope>
Posted
Updated 25-Feb-16 21:14pm

1 solution

Hi,
Please try this.
C#
public string GetCountryDetails(string xmlstring)
    {
        try
        {
            string bodyxml = OperationContext.Current.RequestContext.RequestMessage.GetBodyAttribute("attributename","namespace");
        }
        catch (Exception ex)
        {

        }
    }
 
Share this answer
 
Comments
Raseeth90 26-Feb-16 3:50am    
I am getting this exception.

Code :-

string bodyxml = OperationContext.Current.RequestContext.RequestMessage.GetBodyAttribute("COUNTRY_ID", "");

O/p:-
This message cannot support the operation because it has been read.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900