Bonjour.
J'ai pour objectif de faire créer un petit Web Service, appelé par mon site ASP.Net via le clic d'un bouton, fait uploader ou héberger un fichier (qui est 1 CV au format .DOC)
Voilà le code au sein du site ASP
Code:
1
2
3
4
5 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sw As New localhost.Service1 sw.UploadFile() End Sub
Et voilà le code du Webd Servive que j'ai réalisé :
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 Imports System.IO Imports System.Web.Services <System.Web.Services.WebService(Namespace := "http://tempuri.org/WebServiceISGI/Service1")> _ Public Class Service1 Inherits System.Web.Services.WebService #Region " Code généré par le Concepteur des services Web " Public Sub New() MyBase.New() 'Cet appel est requis par le Concepteur des services Web. InitializeComponent() 'Ajoutez votre code d'initialisation après l'appel InitializeComponent() End Sub 'Requis par le Concepteur des services Web Private components As System.ComponentModel.IContainer 'REMARQUE : la procédure suivante est requise par le Concepteur des services Web 'Elle peut être modifiée en utilisant le Concepteur des services Web. 'Ne la modifiez pas en utilisant l'éditeur de code. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents TextBox1 As System.Windows.Forms.TextBox Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.TextBox1 = New System.Windows.Forms.TextBox Me.Button1 = New System.Windows.Forms.Button Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(17, 17) Me.Label1.Name = "Label1" Me.Label1.TabIndex = 0 Me.Label1.Text = "Chercher votre VB : " ' 'TextBox1 ' Me.TextBox1.Location = New System.Drawing.Point(101, 17) Me.TextBox1.Name = "TextBox1" Me.TextBox1.TabIndex = 0 Me.TextBox1.Text = "" ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(199, 17) Me.Button1.Name = "Button1" Me.Button1.TabIndex = 0 Me.Button1.Text = "OK" ' 'OpenFileDialog1 ' End Sub Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) 'CODEGEN : cette procédure est requise par le Concepteur des services Web 'Ne la modifiez pas en utilisant l'éditeur de code. If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub #End Region Dim f As FileInfo <WebMethod()> Public Function UploadFile() As String OpenFileDialog1.ShowDialog() End Function Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk TextBox1.Text = OpenFileDialog1.FileName End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try f = New FileInfo(TextBox1.Text) f.CopyTo("C:\Inetpub\wwwroot\ISGI\DossierCV") Catch ex As Exception End Try End Sub End Class
Lors après de l'appel du service dans le site et le clic sur le bouton, je me trouve face à l'erreure suivante :
Avez vous une idée pour résoudre le problème, ou une autre méthode pour héberger un fichier à l'aide su Web Service ?Citation:
Erreur du serveur dans l'application '/ISGI'.
--------------------------------------------------------------------------------
System.Web.Services.Protocols.SoapException: Le serveur n'a pas pu traiter la demande. ---> System.InvalidOperationException: Vous ne pouvez pas afficher une boîte de dialogue modale ou un formulaire lorsque l'application ne s'exécute pas en mode UserInteractive. Spécifiez le style ServiceNotification ou DefaultDesktopOnly pour afficher une notification à partir d'une application de service. at System.Windows.Forms.CommonDialog.ShowDialog() at WebServiceISGI.Service1.UploadFile() in c:\inetpub\wwwroot\WebServiceISGI\Service1.asmx.vb:line 88 --- Fin de la trace de la pile d'exception interne ---
Merci