locked
Web service data transfer in XML & Binary RRS feed

  • Question

  • User88744855 posted

    i always saw that when data transfer occur then it always transfer in xml format but what is binary format data transfer in web service and when data transfer occur in binary format?

    how to customize a web service to send data in binary format.

    thanks

    Wednesday, July 2, 2014 3:13 AM

Answers

  • User-417640953 posted

    Hi mou_inn,

    i know that web service means it will always use SOAP. is it true......web service always use SOAP as a protocol for transferring data between service end & client end?

    Your are right, the web service using the soap protocol exchange data between server and client side by default. That because it is XML based and cross platform and

    recommended by W3C.

    soap means xml. the data will wrapped in many xml tag and will pass to server or client. so how binary can be use in web service?

    when binary data travel in web service then how xml look like ?

    In soap body, binary data usually encoded to base64 string like below.

    <m:data xmlns:m=’http://example.org/people’ >
      <photo>/aWKKapGGyQ=</photo>
      <sound>sdcfo2JTiXE=</sound>
      <hash>Faa7vROi2VQ=</hash>
    </m:data>
    

    also tell me how many ways data is serialized in web service? i know default is xml but is there other exist??

    Web service also support the Json data format based on the http protocol. If user client using the ajax inside a browser to call your web service,

    then JSON is the hands-down winner because it essentially is the serialization of Javascript objects. This property of JSON makes it a much better

    fit for client-side scripting in Javascript.

    • XML is designed for text markup.
    • JSON is a general data structures serialization format.

    Hope this helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 3, 2014 10:09 PM

All replies

  • User-417640953 posted

    what is binary format data transfer in web service and when data transfer occur in binary format?

    how to customize a web service to send data in binary format.

    Hi mou_inn,

    Thanks for your post.

    In asp.net web service, we usually use the binary data format pass the file stream to server side such as image file, document file and video file.

    Like below.

    [WebMethod]
    public bool SaveDocument( Byte[] docbinaryarray, string docname)
    {
    	string strdocPath;
    	strdocPath = "C:\\DocumentDirectory\\" + docname;
    	FileStream objfilestream =new FileStream(strdocPath,FileMode.Create,FileAccess.ReadWrite);
    	objfilestream.Write(docbinaryarray,0,docbinaryarray.Length);
    	objfilestream.Close();
    
    	return true;
    }
    

    In the client side we call this method like that :

    string sFile = "<file path>";
    
    private void button1_Click(object sender, System.EventArgs e)
    {
    	FileStream objfilestream = new FileStream(sFile,FileMode.Open,FileAccess.Read);
    	int len = (int)objfilestream.Length;
    	Byte[] mybytearray = new Byte[len];
    	objfilestream.Read(mybytearray,0,len);
    	localhost.Service1 myservice = new localhost.Service1();
    	myservice.SaveDocument(mybytearray,sFile.Remove(0,sFile.LastIndexOf("\\")+1));
    	objfilestream.Close();
    }
    

    For how the web service pass a binary data through soap protocol, you can refer to below.

    http://stackoverflow.com/questions/2641820/transferring-binary-data-through-a-soap-webservice

    http://stackoverflow.com/questions/12708119/large-binary-over-asmx-web-service

    Hope this helps, thanks.

    Regards!

    Thursday, July 3, 2014 1:42 AM
  • User88744855 posted

    thanks for reply. i know that web service means it will always use SOAP. is it true......web service always use SOAP as a protocol for transferring data between service end & client end?

    soap means xml. the data will wrapped in many xml tag and will pass to server or client. so how binary can be use in web service?

    when binary data travel in web service then how xml look like ?

    to be very honest soap, xml & binary data issue is not very clear to me regarding usage in web service. so give me a url which guide me how they are used in web service.

    also tell me how many ways data is serialized in web service? i know default is xml but is there other exist??

    looking for bit detail discussion. thanks

    Thursday, July 3, 2014 3:35 AM
  • User-417640953 posted

    Hi mou_inn,

    i know that web service means it will always use SOAP. is it true......web service always use SOAP as a protocol for transferring data between service end & client end?

    Your are right, the web service using the soap protocol exchange data between server and client side by default. That because it is XML based and cross platform and

    recommended by W3C.

    soap means xml. the data will wrapped in many xml tag and will pass to server or client. so how binary can be use in web service?

    when binary data travel in web service then how xml look like ?

    In soap body, binary data usually encoded to base64 string like below.

    <m:data xmlns:m=’http://example.org/people’ >
      <photo>/aWKKapGGyQ=</photo>
      <sound>sdcfo2JTiXE=</sound>
      <hash>Faa7vROi2VQ=</hash>
    </m:data>
    

    also tell me how many ways data is serialized in web service? i know default is xml but is there other exist??

    Web service also support the Json data format based on the http protocol. If user client using the ajax inside a browser to call your web service,

    then JSON is the hands-down winner because it essentially is the serialization of Javascript objects. This property of JSON makes it a much better

    fit for client-side scripting in Javascript.

    • XML is designed for text markup.
    • JSON is a general data structures serialization format.

    Hope this helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 3, 2014 10:09 PM