Re: Really basic newbie question
From: Dino Chiesa [Microsoft] (dinoch_at_online.microsoft.com)
Date: 06/16/04
- Next message: Arun Kumar: "Invoking WebMethods WebService Issue"
- Previous message: Dino Chiesa [Microsoft]: "Re: wsdl.exe source code"
- In reply to: Mark Rae: "Really basic newbie question"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 15 Jun 2004 20:05:53 -0400
"Mark Rae" <mark@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:%23aVyii7TEHA.3988@TK2MSFTNGP10.phx.gbl...
> The above doesn't cause any errors, and pretty much works as I expect,
apart
> from the format of the output. It displays as follows:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <string xmlns="http://www.markrae.co.uk/"><?xml version="1.0"
> encoding="utf-8"?> <!--This is a comment--> <Return> <Postcode>AB1
> 1BB</Postcode> <ReturnValue>1</ReturnValue> </Return></string>
>
> whereas I'd expect it to display as:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <string xmlns="http://www.markrae.co.uk/"></string>
> <!--This is a comment-->
> <Return>
> <Postcode>AB1 1BB</Postcode>
> <ReturnValue>1</ReturnValue>
> </Return>
>
>From what point in the code are you displaying it? and to what output
stream (or device)?
When I try it, by printing it right after I call that routine, it displays
the way you expect.
> I'm sure I'm missing something completely obvious!
>
> Any assistance gratefully received.
Ok, then
you didn't ask but,
I would suggest you do not serialize your data into xml and then stuff it
into a string. No point in doing that. You have to wade through all the
XML writing nonsense, and it's just too much work.
Rather than use XmlTextWriter to format an XML doc and then write it into a
memory stream and read it into a string....
Just fill an object and return the object. All the XML is done
automatically for you.
example:
//-------code begins----------------------------------------
namespace Validation
{
[System.Xml.Serialization.XmlRoot("Return")]
public class PostCodeValidation_Type
{
public string Postcode;
public int ReturnValue;
}
public class CValidation2
{
public PostCodeValidation_Type ValidateUKPostCode(string input) {
PostCodeValidation_Type r = new PostCodeValidation_Type();
r.Postcode= input;
r.ReturnValue= 1;
return r;
}
public static void Main() {
try {
CValidation2 me = new CValidation2();
PostCodeValidation_Type t= me.ValidateUKPostCode("VeryNice");
// --
// this is just for display purposes.
// if used within a webservice, the PostCodeValidation_Type
would be implicitly serialized when you return it.
System.Console.WriteLine("\nVersion2:");
System.Xml.Serialization.XmlSerializer s= new
System.Xml.Serialization.XmlSerializer(typeof(PostCodeValidation_Type));
System.Xml.Serialization.XmlSerializerNamespaces ns = new
System.Xml.Serialization.XmlSerializerNamespaces();
ns.Add( "", "" );
s.Serialize(System.Console.Out, t, ns);
System.Console.WriteLine("\n");
// end display logic
// --
}
catch (System.Exception e1){
System.Console.WriteLine("Exception: \n" + e1);
}
}
}
}
//-------code ends----------------------------------------
>
> Best regards,
>
> Mark Rae
>
>
- Next message: Arun Kumar: "Invoking WebMethods WebService Issue"
- Previous message: Dino Chiesa [Microsoft]: "Re: wsdl.exe source code"
- In reply to: Mark Rae: "Really basic newbie question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|