I need to use a web service that was provided to me and that uses SOAP with attachments as a means of communication. It also uses WS-Security 1.0 as a form of authencation (user and pass in plain text).
I will be working on VB.NET and my experience with web services is very slim, and goes as far as creating a WCF web service, adding the service reference in another project thus creating a proxy class and using the methods.
I have searched the internet and found that there is no native support for SwA in VB.NET, is this correct? An example on how i can approach the communication and some indication on where i can be more aware of these concepts would be superb.
You can send and receive SOAP messages that include binary data (such as PDF files or JPEG images) as attachments.
The MIME multipart mechanism for encapsulation of compound documents can be used to bundle entities related to the SOAP 1.1 message such as attachments. Rules for the usage of URI references to refer to entities bundled within the MIME package are specified.
Why not just put your attachment data into a byte array and send that?
Public Class SoapPackage
Public Property AttachmentName() As String
Get
Return m_AttachmentName
End Get
Set
m_AttachmentName = Value
End Set
End Property
Private m_AttachmentName As String
' put your file data in here
Public Property AttachmentData() As Byte()
Get
Return m_AttachmentData
End Get
Set
m_AttachmentData = Value
End Set
End Property
Private m_AttachmentData As Byte()
End Class
Streaming your file into the byte array with something along these lines (open a stream for the attachment, pass it into this function):
Public Shared Function StreamToByteArray(input As Stream) As Byte()
Dim buffer As Byte() = New Byte(16 * 1024 - 1) {}
Using ms As New MemoryStream()
Dim read As Integer
While (InlineAssignHelper(read, input.Read(buffer, 0, buffer.Length))) > 0
ms.Write(buffer, 0, read)
End While
Return ms.ToArray()
End Using
End Function
edit:
Just learned that my StreamToByteArray
function can be replaced with simply:
Dim filePath as String = "Path\to\file"
Dim fileBytes as Byte() = System.IO.File.ReadAllBytes(filePath)
In a recent project of mine I had to communicate in c# with a soap WebService. To deal with that I made my full soapenvelope in a string and send it to the web service with a HttpWebRequest. With the WebRespons you can then read out the response of the webservice and put it back into a string. This string you can convert to a XmlDocument to read out the object that you want.
You can easily make the soapenvelope as you want with a loop (if necessary) and also put the authencation in the header of the soapenvelope (did it this way)
To get the correct soapenvelope syntax of your web service I can advise you to use SOAPUI, a great small application that helped me a lot ! This way you will notice where to put the authencation, ..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With