views:

37

answers:

1

Alright...I have kind of a big quesstion...ok here goes...Usually if i understand it well...web services work in a way that i write a method to get some data from the database and then some other user/client adds a reference and calls my service and gets the data...now in my case i have to get the data and actually post it to the user/client in xml(in soap maybe) i guess....so here is what i do...

[Serializable]
public class MyClass
{  [SoapAttribute]
   public int id;
    [SoapIgnore]
        public int ToSkip;
} 

String XmlizedString = null; 
            MyClass obj= new MyClass ();
            MemoryStream memoryStream = new MemoryStream ( );
            XmlTypeMapping myMapping =
            (new SoapReflectionImporter().ImportTypeMapping
            (typeof(MyClass)));
            XmlSerializer xs = new XmlSerializer (myMapping);
            XmlTextWriter xmlTextWriter = new XmlTextWriter ( memoryStream, Encoding.UTF8 );

            xs.Serialize ( xmlTextWriter, obj );
            memoryStream = ( MemoryStream ) xmlTextWriter.BaseStream;
            XmlizedString = UTF8ByteArrayToString ( memoryStream.ToArray ( ) );
            using (System.Net.WebClient client = new System.Net.WebClient())      
           {
            // performs an HTTP POST
            status= client.UploadString("http:/somewebservice.com/" + webServiceName,                 XmlizedString); 
            }

So basically....I serialize it to xml(and soap) and convert it to string and then upload this string to the web service url...... I just want to know if what i am doing is right?...i want to basically get the data convert it to soap xml and then send it over to the user's web service url....please help me out...

+1  A: 

Is this wsdl-based webservice? If yes, then just use your IDE or some tool to generate static-typed client wrapper.

In .NET environment, you can use visual studio or wsdl.exe

Don't send raw data to url and don't try to parse response manually, that's insane. Especially with these complex SOAP-based webservices.

lubos hasko
is it a big problem if i just post straight xml(as a string) to an url to provide the data...i am sorry but what are the issues here?
Misnomer
there are basically two issues with it. first you will need to write more code = more time wasted than necessary and the second issue is maintenance, if client webservice interface changes, you will have to manually figure out what has changed and update your manually written code rather than just regenerate client code by a tool. technically what you are doing is not wrong, it's just wrong from business point of view.
lubos hasko