473,378 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

XML Serialization and SOAP

1,047 Expert 1GB
I created a piece of code with which I can create an XML which look like this:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <test xmlns:test="http://www.test.nl">
  3.   <a>A</a>
  4.   <b>
  5.     <c>1</c>
  6.     <c>2</c>
  7.     <c>4</c>
  8.     <c>3</c>
  9.   </b>
  10. </test>
I did this creating a class using XSD.exe on the following XSD:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  3.   <xs:element name="test">
  4.     <xs:complexType>
  5.       <xs:sequence>
  6.         <xs:element name="a" type="xs:string" />
  7.         <xs:element name="b">
  8.           <xs:complexType>
  9.             <xs:sequence>
  10.               <xs:element maxOccurs="unbounded" name="c" type="xs:string" />
  11.             </xs:sequence>
  12.           </xs:complexType>
  13.         </xs:element>
  14.       </xs:sequence>
  15.     </xs:complexType>
  16.   </xs:element>
  17. </xs:schema>

My question:
If I want to send this xml as a request to a SOAP server, how do I add the SOAP-envelope?

I tried to do this:
1) define a class for the SOAP envelope
Expand|Select|Wrap|Line Numbers
  1.     [XmlInclude(typeof(SOAP))]
  2.     [Serializable]
  3.     public class SOAP
  4.     {
  5.         public string Head { get; set; }
  6.         public object Body { get; set; }
  7.     }
When I try to insert my XML thing into this like this:
Expand|Select|Wrap|Line Numbers
  1. SOAP x3 = new SOAP { Head = "x1", Body = x2 };
  2.             XmlSerializer xs3 = new XmlSerializer(x3.GetType(), "");
  3.             XmlWriterSettings xws3 = new XmlWriterSettings();
  4.             xws3.Indent = true;
  5.             xws3.Encoding = Encoding.UTF8;
  6.             XmlWriter xw3 = XmlWriter.Create("test3.xml", xws3);
  7.             xs3.Serialize(xw3, x3, namespaces);
It fails with an 'InvalidOperationException' on the xs3.Serialize.
('x2' is the object holding the XML shown earlier...)
Apr 23 '16 #1
4 3636
madankarmukta
308 256MB
Could you please paste the contents of here X3 just before the Serialize sentence.
Apr 24 '16 #2
Luuk
1,047 Expert 1GB
I made some changes to above code (I will edit my original post too)

the contents of X3 is (copied from 'Immediate Window':
Expand|Select|Wrap|Line Numbers
  1. x3
  2. {CreateXML_1.SOAP}
  3.     Body: {test}
  4.     Head: "x1"
  5. x3.Body
  6. {test}
  7.     a: "A"
  8.     aField: "A"
  9.     b: {string[0x00000004]}
  10.     bField: {string[0x00000004]}
  11. x3.Head
  12. "x1"
If you was hoping to see something else please give directions on how to get that info... ;)


BTW: If I change the definition of 'Body' (which is currently an 'object' to 'test' than I do no get the error. But that's not what I want, because I need the possibility to send other XML's to the same server.

After changing 'object' to 'test', i'm getting this test3.xml:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <SOAP xmlns:test="http://www.test.nl">
  3.   <Head>x1</Head>
  4.   <Body>
  5.     <a>A</a>
  6.     <b>
  7.       <c>1</c>
  8.       <c>2</c>
  9.       <c>4</c>
  10.       <c>3</c>
  11.     </b>
  12.   </Body>
  13. </SOAP>
I'm loosing the 'test'-rootTag, which I also do not like ;)
Apr 24 '16 #3
madankarmukta
308 256MB
If I understood your question correctly, there might be some problem the format for the Header contents. Probably you could look into http://stackoverflow.com/questions/2...nvelope-in-net

Hope this helps.
Apr 25 '16 #4
Luuk
1,047 Expert 1GB
If you are referring to the answer "I was able to solve this by using an XLST to wrap the XML in soap"...

This is (I tihkn) a no go, because this would probable be tooo slow. (and to complex to implement (for /me ;)).

But i'll give it a test tomorrow.... ;)
Apr 26 '16 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Hasani | last post by:
If I have a base class that is derived from many classes, and I want to make all the classes serializable. Is there a way I can do this from the base class or must I add to every class, even if...
4
by: Brian Keating | last post by:
wonder if anyone can help me here, i've a framework 1.1 dataset which i serialize in framework 1.1 and deserialize in framework 2.0. This is fine, problem is that i want to modify some of the...
0
by: umhlali | last post by:
I get the following exception when my VB.NET app calls a Java web service that returns an array of objects. The same call works for a single object though. So looks like there is no problem...
0
by: Cleo | last post by:
Hi, I am trying to call a WebService Method written in Weblogic from VB.NET and I am getting the following error. I am using SOAP Caal s from VB.NET. Please find the wsdl file and my code. ...
3
by: parrot toes | last post by:
Summary: I have been trying to make requests of a web service provided by Axis using a dotnet client with code generated by wsdl.exe and have been getting exceptions when trying to process the...
0
by: Daniel Thune, MCSE | last post by:
I am having a problem with formatting a SOAP Header in a .Net client. The client calls a Java Axis 1.1 based web service. In order to authenticate the caller, the web service call is intercepted by...
2
by: Angelos Karantzalis | last post by:
Hi y'all, we're using a bunch of classes in a project, that we wanted to convert to-from xml easily. So, we defined XmlAttribute annotations for our class members and all worked fine. The Xml...
3
by: JRey | last post by:
Does .Net generate the classes for Faults when they are specified in the WSDL. I tried defining them and then generating a proxy, and it did not appear to do it. On the Java side it did generate...
6
by: John Glover | last post by:
I'm having a very strange problem with XML serialization. I'm writing web services which pass instances of various classes back and forth as parameters and return values of web methods. The...
3
by: Siva | last post by:
Hi all, I want to Convert a WSDL to a SOAP message. Is there any way to do this. I am using .NET 2.0 Thanks in Advance Siva
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.