WCF/WF - response from WCF service - Asked By AJMAL YAZDANI on 29-Jul-10 02:25 AM

I have a WCF service that will call by clinet application to put a XML file as a Request. Now I want 2 conditional Response to client,

1. If XML is Invalid, then response should be, "Your Data is not Valid" (I have defined a method to check XML is within WCF service)
2. If XML is valid, then response should be, "Your Data is Valid".

How can we achieve is term of response from XML?

[DataContract]

public class Request

{

[DataMember]

public String strXML { get; set; }

}



[DataContract]

public class Response{

//TODO : We should be here.

}



Sasha Kotlo replied to AJMAL YAZDANI on 29-Jul-10 03:10 AM
Hmm, I'm trying to understand here what exactly is troubling you? Can you actually explain your problem? Having 2 responses if fine, a simple condition will accomplish that so what exactly is a problem?

Regards.
AJMAL YAZDANI replied to Sasha Kotlo on 29-Jul-10 03:36 AM
hello Sasha Kotlo,

I m putting this post for just a sample application (if anyboday have), otherwise it is fine.

I m trying here and hopefully achieve this.


Anyway, big thanks for reply....
Sasha Kotlo replied to AJMAL YAZDANI on 29-Jul-10 03:47 AM
[WebMethod]
public string VerifyXmlRequest(string XML)
{
XmlDocument request = new XmlDocument();
request.LoadXml(XML);

XmlNode someTestNode = request.SelectSingleNode("//XmlRequestRoot/SomeNode/RequestType");

if(someTestNode != null && someTestNode.InnerText == "CorrectLayout")
{
return true;
}

// in any other case request isn't valid so return invalid message
return false;
}

now you'd use it like this:

SomeServiceName serviceAPI = new SomeServiceName();
if(serviceAPI.VerifyXmlRequest(xmlstring))
{
Response.Write("Request accepted!");
}
else
{
Response.Write("Invalid request!");
}

if this what you wanted to do?

Best of luck.