DIME message with VBScript
To implement a client and a Web Services with .NET that uses attachements is pretty simple. WSE does a lot of stuff for us. But, if we want consume a web service with attachement from a VB or VBScript client we have to write more code.
First of all we have to download Microsoft SOAP Toolkit 3.0 which provides an object model for DIME also. Then we should have a WebMethod with attachements, such as the following simple sample:
[WebMethod]
public string GetLastImage()
{
DimeAttachment attachment = new DimeAttachment("image/jpeg",
TypeFormatEnum.MediaType, Server.MapPath(@"\images\Test.jpg"));
HttpSoapContext.ResponseContext.Attachments.Add(attachment);
return "Test.jpg";
}
On the client side we can then create a VBS file as following:
WScript.Echo ("-----Start------")
' Connect to the web service
EndPointURL = "http://webstudy/WebServices/DimeSample.asmx";
Set connector = CreateObject("MSOSOAP.HttpConnector30")
connector.Property("EndPointURL") = EndPointURL
connector.Connect
' Define SOAP message
connector.Property("SoapAction") = "urn:pierregreborio-it/GetLastImage"
connector.BeginMessage
Set Serializer = CreateObject("MSOSOAP.SoapSerializer30")
Serializer.Init connector.InputStream
Serializer.StartEnvelope
Serializer.StartBody
Serializer.StartElement "GetLastImage", "urn:pierregreborio-it"
Serializer.EndElement
Serializer.EndBody
Serializer.EndEnvelope
connector.EndMessage
' Post the message and get the response with the DIME parser (this is a DIME message)
Set Reader = CreateObject("MSOSOAP.SoapReader30")
Set Parser = CreateObject("MSOSOAP.DimeParser30")
Reader.LoadWithParser Connector.OutputStream, Parser
If Not Reader.Fault Is Nothing Then
WScript.Echo(Reader.FaultString.Text)
Else
' Get the image from the attachments
Set ImageAttach = Reader.Attachments.Item(0)
FileName = "ReceivedImage.jpg"
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(FileName)) Then
fso.DeleteFile FileName
End If
ImageAttach.SaveToFile FileName
End If
WScript.Echo("-----Done------")
This sample doesn't contains all error controls but gives an idea how to get an attachment with SOAP Toolkit 3.0...hopefully.