I don't know how to use xsd message when i consume the service

Topics: General Discussion Forum
Jul 19, 2009 at 11:50 AM
Edited Jul 19, 2009 at 11:51 AM

I use WSSF pattern , i used the tutorial , but when i consume the service the return type " responseMessage ( xsd ) " contain property of PartLevel, so how to get the return value

Jul 19, 2009 at 3:43 PM

Sorry but I not sure about your question. Are you asking for the return type of PartLevel?

Can you describe further the proxy class and types that you are using?

 

Thanks,

Hernan

Jul 19, 2009 at 4:04 PM
Edited Jul 19, 2009 at 4:09 PM


good afternoon Mr.Hernan,
i am sorry because i don't have big knowledge in factory , that i am try to learn :) .
i don't know how to use the xsd message (with partLevel class ). and if i want to return datatable , how can i use xsd message.

this is the class i consume the service on it .


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using System.IO;
using System.Xml;
using System.Text;
using WCFNews.MessageContracts;



namespace WCFNews.ServiceImplementation
{
public partial class NewsService:NewsServiceBase
{
int maxNoNews = 10;
string newsPage = "newsDetails.aspx";
string setTarget = "_parent";


public override WCFNews.MessageContracts.ResponseNews AddNewsRequirement(WCFNews.MessageContracts.RequestNews request)
{

string webName =request.NewsRequirment.WebName;
string newsDate = request.NewsRequirment.NewsDate;
string newsTitle = request.NewsRequirment.NewsTitle;
string newsText = request.NewsRequirment.NewsText;
try
{

XmlDocument doc = new XmlDocument();

string path = webName;
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.ReadWrite);
doc.Load(fs);
int count = doc.GetElementsByTagName("div").Count;
if (count < maxNoNews)
{
XmlElement xeDiv = doc.CreateElement("div");

XmlAttribute idDiv = doc.CreateAttribute("ID");
idDiv.Value = (count + 1).ToString();
xeDiv.SetAttributeNode(idDiv);

XmlAttribute classDiv = doc.CreateAttribute("Class");
classDiv.Value = "message";
xeDiv.SetAttributeNode(classDiv);

XmlElement d = doc.CreateElement("dd");
d.InnerText = newsDate;

XmlElement br = doc.CreateElement("br");

XmlElement a = doc.CreateElement("a");

XmlAttribute href = doc.CreateAttribute("href");
href.Value = newsPage;
a.SetAttributeNode(href);

XmlAttribute target = doc.CreateAttribute("target");
target.Value = setTarget;
a.SetAttributeNode(target);

a.InnerText = newsTitle;


XmlElement Text = doc.CreateElement("NewsText");
Text.InnerText = newsText;

xeDiv.AppendChild(d);
xeDiv.AppendChild(br);
xeDiv.AppendChild(a);
xeDiv.AppendChild(Text);

doc.DocumentElement.InsertAfter(xeDiv, doc.DocumentElement.LastChild);

XmlNodeList nodeList = doc.GetElementsByTagName("News");

nodeList[0].AppendChild(xeDiv);
fs.Close();
FileStream xmlFS = new FileStream(path, FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite);

doc.Save(xmlFS);


xmlFS.Close();
WCFNews.BusinessEntities.ItemLevel itemLevel = new WCFNews.BusinessEntities.ItemLevel();

ResponseNews response = new ResponseNews();
WCFNews.DataContracts.PartLevel partLevel = TranslateBetweenItemLevelAndPartLevel.TranslateItemLevelToPartLevel(itemLevel);



return response;

}

}
catch(Exception ex)
{


return null;

}





}
}
}

 


thank you for helping.

Karim.

Jul 19, 2009 at 7:08 PM

Hi Karim,

As I see you are building an XML and at the end of the operation you call the translator and return the partLevel element (the latter seem to have no relationship with the previous XML manipulation).

Regarding the XsdMessage element, is basically a "proxy" artifact that reference an XSD schema type (not a DataContract element). In your particular case, the  "WCFNews.DataContracts.PartLevel" seem to be a DataContract element so you won't use a XsdMessage element there. 

Back to your scenario, I assume that you want to create an XML document with the data from the request parameter. If that the case, then you may use the translator to set your business entity class and serialize that class (using XML Serializer) to your file so you don;t need to do all the cost and error prone XML document operations.

Then you simply get your partLevel DataContract populated from whatever business operation you have and you are done. Let me know if I missed something (or missed the point completly :-)

Regards,

Hernan

Jul 26, 2009 at 11:55 AM

Hi Mr. Hernan.

that's so kind of you for assisted me, that's exactly what i mean for this article.

now it's working find , and i understood it :)

Regards

Karim