473,668 Members | 2,583 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Serialization and SOAP

1,047 Recognized Expert Top Contributor
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 'InvalidOperati onException' on the xs3.Serialize.
('x2' is the object holding the XML shown earlier...)
Apr 23 '16 #1
4 3726
madankarmukta
308 Contributor
Could you please paste the contents of here X3 just before the Serialize sentence.
Apr 24 '16 #2
Luuk
1,047 Recognized Expert Top Contributor
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 Contributor
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 Recognized Expert Top Contributor
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
1573
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 it's parent class has the attribute. I'm thinking no from what I've seen on google so far.
4
7481
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 records in framework 2.0 and serialize the data so framework 1.1 can deserialize it and do what it required. Is this possible?
0
2492
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 serializing the object but there seems to be a problem serializing an array of objects. Any help will be appreciated "Cannot assign object of type System.Object to an object of type ElectronicWallet.C2PTest.PaymentItem." :...
0
2241
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. Any help would really be appreciated. Thx
3
9791
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 response. As a result of seraching news groups I guessed that the SOAP response defines an array element in a way that causes the dotnet deserialization routines to put the content in a generic object array (object) BUT the content is supposed to...
0
4665
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 another web service that validates a security token in the header. I have pasted my current SOAP message that my code sends as captured from a trace function that I added. Below that is a sample SOAP message that the developer of the web...
2
2470
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 stream came from an external source with a custom xml schema, so we had no alternative. However, along the way we came to the point that we must expose those classes as return types for a web service. Returning an instance of a class through the...
3
10285
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 the class and the ability to serialize that class when putting it on the wire. I was hoping a .Net client would create the appropriate exception class defined in the WSDL and deserialize the message into the appropriate exception class.
6
6054
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 problem is that in my derived classes, the XML that is automatically generated is lacking the properties of the base class. For example: public class MyBaseClass { public MyBaseClass ( ) { } private string myVariable;
3
9430
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
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8797
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8656
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7401
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5681
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4205
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.