开发者

What is best way to post data to an url if someone does not call an web service?

开发者 https://www.devze.com 2023-01-07 14:03 出处:网络
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

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.UT开发者_如何学JAVAF8 );

            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...


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消