Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to get incoming request in WCF Service ?

How to check some tags are present in that incoming request ?

I need to receive the incoming request as STRING and convert it into XML and then to process...

What I have tried:

C#
string ssssss = OperationContext.Current.RequestContext.RequestMessage.GetReaderAtBodyContents().ToString();                
try
{
	xmlDocument.LoadXml(ssssss);

	xmlNodeList = xmlDocument.SelectNodes("//COUNTRY_ID");
	if (xmlNodeList.Count > 0)
		getPinRequest.COUNTRY_ID = xmlNodeList[0].InnerText.Trim();
	else
		bXMLSerializeFailed = true;

	xmlNodeList = xmlDocument.SelectNodes("//COUNTRY_NAME");
	if (xmlNodeList.Count > 0)
		getPinRequest.COUNTRY_NAME = xmlNodeList[0].InnerText.Trim();
	else
		bXMLSerializeFailed = true;

}
catch (Exception ex)
{
	bXMLSerializeFailed = true;
	throw ex;
}

O/P:-

<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 21-Feb-16 23:10pm
v2
Comments
Suvabrata Roy 22-Feb-16 5:13am    
http://forums.asp.net/t/1983492.aspx?How+to+send+xml+via+post+to+wcf+service
Kornfeld Eliyahu Peter 22-Feb-16 6:05am    
To validate an XML you should use XSD (XML Schema Definition)...
Check this: https://msdn.microsoft.com/en-us/library/bb387037.aspx

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