How to build XML String from XSD then send to Web Service

HI....

I need some guidance please.  I'm pretty new to XML and Web Services and need direction.

Using VS2005 and Framework 2.0 I need to build an XML string that will be sent via a Windows Forms client to a Web service.  The folks who wrote this Web Service didn't make things very easy for using a .Net Proxy Class to create a client application.

Here's the WSDL (fragment) for the Method that I need to consume....

<s:element name="SaveData">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="xml" type="s:string" />
      </s:sequence>
    </s:complexType>
</s:element>

I do have an XML sample for the string that I need to build.  From that sample I've used 'xsd.exe' to build a schema and again 'xsd.exe' to generate classes.

My plan is to update the appropriate properties in these Classes and then create an XML string that will subsequently be sent to the Web Service via a SoapClient.

I'm stuck at how to actually create/populate the XML string once I've updated the properties in the generated classes.

Help please!!!!!

Thanks,

Dave

0
dceanes
11/10/2008 3:53:58 PM
asp.net.xml-web-services 7071 articles. 0 followers. Follow

5 Replies
523 Views

Similar Articles

[PageSpeed] 3

Use the XmlSerializer, something like this (haven't had time to test):

 

StringBuilder sb = new StringBuilder();
using (XmlWriter writer = XmlWriter.Create(sb))
{
    XmlSerializer ser = new XmlSerializer(typeof(MyClass));
    ser.Serialize(writer, myObject);
}
string xmlString = sb.ToString();
 
John Saunders | MVP – Connected System Developer
0
johnwsaunders3
11/10/2008 6:28:04 PM

Thanks John...  That definately put me on the right track.  I have a couple of questions if you don't mind.

I'm using the following code:

            // Build the xml string
            StringBuilder sb = new StringBuilder();
           
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Encoding = Encoding.UTF8;
            settings.Indent = true;
            //settings.OmitXmlDeclaration = true;
            //settings.NewLineOnAttributes = true;


            using (XmlWriter writer = XmlWriter.Create(sb, settings))
            {
                XmlSerializer ser = new XmlSerializer(typeof(SaveOrder));
                ser.Serialize(writer, so);
            }

            string xmlString = sb.ToString();

that produces this XML:

<?xml version="1.0" encoding="utf-16"?>
<SaveOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" username="xxx" pwd="xyz" xmlns="urn:save-order-schema">
  <Header>
    <Program>Test</Program>
    <Process>Shipping</Process>
    <BillTo Company="LaZBoy" Address1="1234 Some St." City="HighPoint" State="NC" />
  </Header>
</SaveOrder>

My first question is: Why does the Xml Declaration say 'encoding="utf-16"' when I have set it to utf8 ?

Second:  How can I shape the first line of the root element so that I get rid of the xmlns:xsi and xmlns:xsd attributes and move the final xmlns= attribute before the other attributes?  In other words I want the line to look like:

<SaveOrder xmlns="urn:save-order-schema" username="xxx" pwd="xyz" >

Thanks,

 Dave
  

0
dceanes
11/10/2008 8:59:33 PM

It will always be UTF-16 if you write to a string, since strings are always Unicode. If you really need a different encoding, you can serialize to a MemoryStream.


John Saunders | MVP – Connected System Developer
0
johnwsaunders3
11/11/2008 3:43:16 PM

how do you pass your xml to web service?

Thanks

0
sema
11/17/2008 5:47:18 PM

I'm sorry, but I have no idea who you're asking, or what question you are asking. Please start a new thread, and please be more specific in your question.


John Saunders | MVP – Connected System Developer
0
johnwsaunders3
11/17/2008 11:03:39 PM
Reply:

Similar Artilces:

xml web service --uploading the file to the xml web service
how can we upload the file in the xml web service 1.i mean what will be the return value in the proxy class 2.and how am i going to send the file to the xml web service----regards Bipul Kumar Here are some links to articles that helped us get this done: http://msdn.microsoft.com/webservices http://www.microsoft.com/downloads/details.aspx?familyid=06255a94-2635-4d29-a90c-28b282993a41&displaylang=en https://www.sys-con.com/dotnet/article.cfm?id=458 Hope this helps....

create valid xml to send to web service based on the schema provided by web service
Problem: I have a web page which is being populated from a dataset containing multiple tables.  I now need to call a web service and send the majority of this data to be incorporate into a mainframe system.  I have been supplied with the schema that the web service will be using to validate the data.  I am new to web services and I am not sure how to take my existing dataset and transform it into an xml document that matches the schema I was provided with. There is a main schema with an element which is a custom complex type.  This custom type consists of an element whi...

Passing an XML string as part of an XML Web Service
Hi there I am not too sure how to explain this but here goes..... I have a Web Service and I need to pass an XML page in the form of a string to a web service. My web service takes in 5 fields and one of those 5 fields is a string which is an xml page in the form of a string. I need to pass that string onto a COM object.Is it possible to pass XML in the form of a string to a web service or will that cause the web service to error?The web service is normally called from a PL/SQL stored procedure. If thats of any use.  Hi You can pass that XML string to the web method as a parameter.See...

How to call a .net web service from another .net web service?
Hi all,I have developed two asp .net web services using visual studio .net 2003.I wish to call one web service from another web service.I tried adding a web reference of the web service in another web service and was able to do so.but i m not able to access the web methods provided by the web servicecould you please suggest a way to go about itExpecting quick replyThanxCharmy try to make sure that you reference it in the web reference and call it properly this is sample  [WebMethod()] public double CalcDistance(int x1, int y1, int x2, int y2) { Calculator.Service1 calc = new...

How to send an XML file to a Web Service (that records the XML file to HD)
I did this because I wanted to send an XML file to another computer, whether it be next to the one I’m using  or in another country. You will need to adapt my example in order for it to work as you want it. All I demonstrate here is that it is possible to send an XML file to another computer using XML Web Services. Let me know if it works for you. The code assumes you can use Visual Studio. Make the Web Service 1. Make a new project, choosing to make a Web Service. 2. In the code behind-page, place the code below. 3. Build the Web Service. Code: <WebMethod()>...

Web service in .NET from Java Web Service
Hi there,I'm pretty new to .net (although i have years of experience with the old vb 6, access 2k, as well as java)... and need some with perhaps either some syntax or something.Here is the wsdl.<wsdl:definitions targetNamespace="http://www.dynix.com/schema/book">−<wsdl:types>−<schema targetNamespace="GetBookInfoByISBN">−<complexType name="BookInfoType">−<sequence><element maxOccurs="1" minOccurs="0" name="Title" nillable="true" type="xsd:string"/><element maxOccurs=&quo...

Sending an XML data as string with a web service as parameter
Hello, I'm trying to send data to a .net webservice with a webservice client on Delphi 2006. The service functions which i'm trying to use has two different versions. I'm using the second one because first one has a Dataset paramater.Second version has string pDataSetXmlContent parameter instead of the pdataset parameter of first one. (They say that second version for Delphi and Java as first one for C#) Versions of Service Functions: 1. int SendDepartmentGeneralInfo(string pUsername, string pPassword, string pIP, string pHospitalCode, *DataSet pDataSet* ) 2. int SendDe...

XML Web service , Web form
hi i hope if u could help me in what i am making so i have a web form that does the collection of the information from the user when he hits the button this data must be sent to the xml web service but this service must deliver this data in xml then i read the information and insert it to the sql serevr Database could you help me becouse iam soo confused about where to start and what is the stuff to search in it iam new in the xml stuff help me pleaseeeeee“To be incredible you must produce great work”Visit My Bloghttp://www.dotnetjunkies.com/WebLog/hussein My first question is why are yo...

XML vs XML Web Services
I'm getting up to speed with XML and have the following questions: 1) Knowing XML means knowing how to design and create XML Web Services? 2) I found the amount of details on XML/XML Web services overwhelming, harder to digest than HTML or a new language. What's the best approach to learn and use it? Thanks.Please mark the post(s) that have helped you as "Answer" 1. No. They are different things 2. I'd start with a basic XML foundation (basic XML, XPath, and XSD), then review the basic WS things: soap, WSDL, and then from there on move to the WS-specs.Tomas Restrepo ...

creating XML or XML Web Services?
Hi, I know XML is basically creating a file that allowed multiple applications to get data from the XML file ... and I am wondering .. why there is XML Web Services? What are the differences between these two? I am trying to create a Session that will keep update the value whenever it navigate to any page ... and get the Session value in multiple applications. In my guess, stores Session[] in XML file should work for what I am trying to do ... but what exactly is this XML Web Services? In what kind of situation we use XML or vice versa? All developers, even novices and hobbyists, must be a...

.NET web services Vs Java Web Services
Hello, does anyone know of a book or good source of information that compares .NET and Java Web Services? (I would like soemthing neutral if possible). I am thinking of approaching this subject for my dissertation? Many Thanks Rob Hi Rob, Last year I had to give a powepoint presentation on Web Services. I noticed some good books at barnes and noble that discussed the subject. These books were specific to Java and discussed Web Services in a very clear fashion. They gave some elementary examples that were easy to understand. I have not yet had the pleasure of creatin .NET Web Servi...

xml stream from client to xml web service
I'm trying to send a serialized object based of an xsd to an xml web service by an xml stream. I've serialized it into a MemoryStream and trying to sent it to the service that I've made. The service should except this xml stream and create a serialized class of his own.   Giving the fact that I need to pass the Object as an xml stream, is it a good choisse to take a MemoryStream class for me? Trying to pass the MemoryStream instance made at the client side I get a compilation error as the instance made at the client side is recognized as a System.Io.MemoryStream while the argum...

send data from web service to local computer, using web services.
hii have a web application, on web server , and a database on my local computer in my office.i want to send data from my web pages to my local database.i think one way is using web services.i used that, but it has permission errors.that web service have this error :  Server Error in '/in' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30180: Keyword does not name a type.Source Err...

XML Web Service as Admin of a Store Web site
I have created an XML Web Service (WebShopManager) with the IBS Store that will serve as an Admin program. I download the Store data tables to a local client where I read, edit and then return data to the Store. The program can function as a logistic centre. Does anyone have experience with this kind of solution? Can this work in reality when we have lots of data in the tables to download? What could be a problem? I imagine this method much more flexible than the ordinary web based admin solutions. Bo Wiklund...