Create Web Services

F

Federico

Hi I want to create a Web Services where I receive a Template DOT word

a file XML and with these I create a Document that a I'll Send as Dime
Attachment.

<WebMethod()> _
Public Function CreateDimeWord(ByVal DotName As String, ByVal
sXML As String) As String
Dim respContext As SoapContext =
ResponseSoapContext.Current


Try
Dim wrdAPP As Object
Dim oWordDoc As Object
Dim strdocPath As String
Dim sr As System.IO.Stream
Dim i As Integer
Dim DocumentName As String
Dim sFileName As String


If respContext.Attachments.Count = 1 Then
sr = respContext.Attachments(0).Stream
DocumentName =
respContext.Attachments(0).Id.ToString.Split(":").GetValue(1).ToString


strdocPath = Application("UploadPath") +
DocumentName


Dim objfilestream = New
System.IO.FileStream(strdocPath, System.IO.FileMode.Create)
Dim buf(sr.Length) As Byte


While ((i =
respContext.Attachments(0).Stream.Read(buf, 0, buf.Length)) > 0)
objfilestream.Write(buf, 0, i)
End While
sFileName = "c:\temp\" & DotName & ".doc"


wrdAPP = CreateObject("Word.Application")
oWordDoc = wrdAPP.Documents.Open(strdocPath, ,
True)
oWordDoc.SaveAs(sFileName)


wrdAPP.Run("WordHelper.Run", sXML)
oWordDoc.Save()
oWordDoc.Close()
oWordDoc = Nothing


Dim dimeAttach As New
DimeAttachment("application/msword", TypeFormat.MediaType, sFileName)
respContext.Attachments.Add(dimeAttach)


Return "1"
Else
Return "0"
End If


Catch ex As FieldAccessException
Return ex.ToString


End Try


End Function


this is the client...in VB6


Private Sub Command1_Click()
On Error GoTo errcode
Dim SOAPReader As MSSOAPLib30.SoapReader30
Dim SOAPSerializer As MSSOAPLib30.SoapSerializer30
Dim SOAPConnector As MSSOAPLib30.SoapConnector30
Dim SOAPParser As DimeParser30
Dim SOAPRcvdAttachments As MSSOAPLib30.IReceivedAttachment
Dim SOAPComposer As DimeComposer30
Dim DownLoadFile As String
Dim SOAPFileAttachment As FileAttachment30
Dim sNomeAllegato As String
Dim allegato As String
Set SOAPConnector = New MSSOAPLib30.HttpConnector30
SOAPConnector.Property("EndPointURL") =
"http://ibcl14/GestioneModelliWS/GestModelli.asmx"
SOAPConnector.Connect


' Set Method Call


SOAPConnector.Property("SoapAction") =
"http://tempuri.org/GestioneModelliWS/GestModelli/CreateDimeWord"


allegato = "E:\COM.dot"
Set SOAPFileAttachment = CreateObject("MSSOAP.FileAttachment30")
SOAPFileAttachment.FileName = allegato
SOAPFileAttachment.DeleteAfterSending = False
'For j = 3 To Len(allegato)
' strTestChar = Mid(allegato, Len(allegato) - j, 1)
' If strTestChar = "\" Then
' sNomeAllegato = Right(allegato, j)
' Exit For
' End If
'Next


SOAPConnector.BeginMessage
' Create DIME composer and serializer objects, then initialize the
' serializer with the composer.
Set SOAPComposer = CreateObject("MSSOAP.DimeComposer30")
Set SOAPSerializer = CreateObject("MSSOAP.SoapSerializer30")
SOAPSerializer.InitWithComposer SOAPConnector.InputStream,
SOAPComposer
' Serializer.Init Connector.InputStream
' Write out the SOAP Envelope and Body start tags.
SOAPSerializer.StartEnvelope
SOAPSerializer.StartBody


' Start the method element.
SOAPSerializer.StartElement "CreateDimeWord",
"http://tempuri.org/"


SOAPSerializer.StartElement "DotName"
SOAPSerializer.WriteString "Prova"
SOAPSerializer.EndElement


SOAPSerializer.StartElement "sXML"
SOAPSerializer.WriteString
"LIBRANET><COMUNICAZIONI><RECORDS><RECORD><id_Comunicazione>62</id_Comunica­zione><id_Installazione>111111</id_Installazione><c_TipoDelibera>DG

</c_TipoDelibera></RECORD></RECORDS></COMUNICAZIONI></LIBRANET>"
SOAPSerializer.EndElement


SOAPSerializer.AddAttachment SOAPFileAttachment
SOAPSerializer.EndElement


' Write out the SOAP Envelope and Body end tags.
SOAPSerializer.EndBody
SOAPSerializer.EndEnvelope


' Tell the serializer that we are finished providing all message
' content (both the SOAP envelope and all attachments).
SOAPSerializer.Finished
SOAPConnector.EndMessage


''''SOAPConnector.BeginMessage
''''
''''Set SOAPComposer = CreateObject("MSSOAP.DimeComposer30")
''''Set SOAPSerializer = New MSSOAPLib30.SoapSerializer30
''''SOAPSerializer.InitWithComposer SOAPConnector.InputStream,
SOAPComposer
''''
''''' Create/Send SOAP Message with Parameter "Number"
''''
''''SOAPSerializer.StartEnvelope
'''' SOAPSerializer.StartBody
'''' SOAPSerializer.StartElement "DownloadFile",
"http://tempuri.org/"
'''' SOAPSerializer.StartElement "DocumentName"
'''' SOAPSerializer.WriteString sNomeAllegato
'''' SOAPSerializer.EndElement
''''' SOAPSerializer.StartElement "sXML"
''''' SOAPSerializer.WriteString "XX"
''''' SOAPSerializer.EndElement
'''' SOAPSerializer.AddAttachment SOAPFileAttachment
'''' SOAPSerializer.EndElement
'''' SOAPSerializer.EndBody
''''SOAPSerializer.EndEnvelope
''''
''''SOAPConnector.EndMessage


Set SOAPReader = New SoapReader30
SOAPReader.Load SOAPConnector.OutputStream
If Not SOAPReader.Fault Is Nothing Then
DownLoadFile = "0"
Else
DownLoadFile = "1"
End If
'Set SOAPReader = New SoapReader30
'Set SOAPParser = New DimeParser30
'If SOAPReader.LoadWithParser(SOAPConnector.OutputStream, SOAPParser)
Then
' Set SOAPRcvdAttachments = SOAPReader.Attachments.Item(0)
' SOAPRcvdAttachments.SaveToFile "C:\downloaded.doc"
' DownLoadFile = "OK"
'Else
' DownLoadFile = "no attachment"
'End If
'MsgBox DownLoadFile
Exit Sub


errcode:
MsgBox Err.Description
Unload Me
End Sub


The Web Services don't work
Why? Thanks a Lot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top