cyclonebri Posted November 13, 2003 Posted November 13, 2003 (edited) Hey everybody, Here's a real fun one that I've been fighting for about a day now so I'd like to throw it out to see if anyone has a solution to what is happening here. I have developed an XMLWeb service, which correctly queries the data that I need and using xpath manipulates the data into the proper form and then places the new data into a new XmlDocument. To instantiate this procedure, I pass an object from the client by ref to the webservice. The object is defined as a class on the webservice, however there is no coding inside the class (the webservice class is basically a struct, as this is how I learned to do this). Everything works as it should and the pass is successful. Inside the class (called cDocument) the cDocument object contains two XmlDocuments, UserSideData, and ServerSideData. These two documents work like documents, store data like documents and even say they are going to return documents, but they don't. When myService is added as a web reference to my client, the two document object variables within the class are showing up as XmlNodes, not XmlDocuments. When I try to access them, then it tells me that there are invalid casts or throws a soap exception. I can send data to the web service and it works fine, but returning the data in the referenced object is where I'm having the problem. Does anyone have any thoughts? Here is some code that I'm using: [CS] //cdocument namespace XMLDataSync { /// <summary> /// Summary description for cDocument. /// </summary> public class cDocument { public System.Xml.XmlDocument m_UserDocument; public System.Xml.XmlDocument m_ServerDocument; public cDocument() { } } } //*********************************************** //in the web service itself: [WebMethod] public void SynchronizeData(ref cDocument myCDocument) { m_LocalcDocument = myCDocument; //sync algortihm runs here, using the myCDocument and comparing to the server data. //once this is run the cDocument m_ServerDocument will be the returning value that will be used to resync on the client side //for now I am just returning the original document, until I get this working I cannot move forward myCDocument.m_ServerDocument = myCDocument.m_UserDocument; } //*************************************************** //ClientSideCode myProject.SyncWebRef.cDocument myCDocument= new cDocument(); //I already have a document ready to send for the user data before doing this myCDocument.m_UserDocument = myDocument; myProject.SyncWebRef.XMLDataSync x_sync_svc = new XMLDataSync(); x_sync_svc.Synchronize(ref myCDocument); //****************HERE IS THE PROBLEM:***************** //This will cause an error: System.Xml.XmlDocument myDoc2 = myCDocument.m_ServerDocument; //even though this should work it doesn't, as the client is thinking that myCDocument.m_ServerDocument and myCDocument.m_UserDocument are xmlnodes, not xmldocuments. [/CS] Thanks in advance for any help! Brian **Edit** After further testing I have realized that I can't send an xmldocument either. I can however do simple objects like strings or integers and they work fine. I am thinking something about the document is getting lost through the passing between the client and the service and that is why it is a node, not a document. Any help is still greatly appreciated. Thanks! Edited November 13, 2003 by cyclonebri Quote
cyclonebri Posted November 13, 2003 Author Posted November 13, 2003 Well I have formed a workaround for this, but it's not the best, although it works. I am allowed to pass a string trhough the service no problem, so I just set two strings inside the document, one for each side, then I just convert the documents to strings and strings to documents as necessary on either side of the transfer. Thanks for looking Anyway! Brian Quote
kajaco Posted December 28, 2004 Posted December 28, 2004 namespace is potential issue I have had similar problems with sending data to a webservice. I found that I was able to submit XML data as an XMLnode, but then was unable to access it with XPath expressions. Then I loaded the OuterXML into a stringbuilder and took out the xmlns ("http://tempuir.org/" in my case). Then I loaded the string into an XMLdocument using the LoadXML method. After that, I was able to use XPath expressions to navigate it. I have also had to do the same thing when trying to transform it with XSL. Pretty strange?! I have done a lot of crazy experiments with XPath expressions using the namespace axis, and setting the namespace in the stylesheet, etc. Nothing has worked. Has anyone else had this problem? Quote
VBAHole22 Posted June 2, 2005 Posted June 2, 2005 I'm having an issue similar to this as well. Wondering if anyone can shed some light. I have a service that I want to pass an XmlDocument to from another service. But when I make a web reference the XmlDocument return type is changed to XmlNode. Is there any way to get an XmlDocument passed along from one service to another and out to the client? Quote Wanna-Be C# Superstar
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.