P
pamelafluente
Hi,
I have written my very first Web Service. And I have some
newbie question.
Here is what I have done (please advice if there is a better way).
I have created a simple service that does the following.
Takes in input a file name and return its content.
Here is the service:
'---------------------------------------
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://localhost/", _
Name:="MyReportServices", _
Description:="Update and displays a file")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetReportByName(ByVal FileName As String) As String
Dim FileNameOnServer = Server.MapPath(FileName)
If Not System.IO.File.Exists(FileNameOnServer) Then
Return "File " & FileNameOnServer & " not found on Server"
End If
Return System.IO.File.ReadAllText(FileNameOnServer)
End Function
End Class
'-----------------------------------------------
I placed the service on my web root.
Then I had to figure out how to call it from a web page.
I didn't have a clue and did the following. Created a new asp.net
page. Placed on it a Button and a TextBox. Added a reference to my
webservice.
And under the Button click handler I wrote:
'-----------------------------------------------
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub ButtonLoadFile_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ButtonLoadFile.Click
Dim MyReportServices As New localhost.MyReportServices
With MyReportServices
Response.Write(.GetReportByName(Me.TextBoxFileName.Text))
End With
End Sub
End Class
'-----------------------------------------------
This seems to work fine (file content appears before the button
and the textbox). Now my questions:
1. If I want to call the service from a simple html page
with just a textbox and a button form. What would the code be?
2. I want to distribute the .asmx so that anyone can use the service
on his/her own server.
In such a case it is correct to have -->
Namespace:="http://localhost/"
or what should it be in order to work independently of the server
where the service is
hosted?
3. I see that the response appears before the button and TextBox.
How would I change the code to make it appear past them?
Please do advice if you see I am not doing things in a right manner.
-Pam
I have written my very first Web Service. And I have some
newbie question.
Here is what I have done (please advice if there is a better way).
I have created a simple service that does the following.
Takes in input a file name and return its content.
Here is the service:
'---------------------------------------
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://localhost/", _
Name:="MyReportServices", _
Description:="Update and displays a file")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetReportByName(ByVal FileName As String) As String
Dim FileNameOnServer = Server.MapPath(FileName)
If Not System.IO.File.Exists(FileNameOnServer) Then
Return "File " & FileNameOnServer & " not found on Server"
End If
Return System.IO.File.ReadAllText(FileNameOnServer)
End Function
End Class
'-----------------------------------------------
I placed the service on my web root.
Then I had to figure out how to call it from a web page.
I didn't have a clue and did the following. Created a new asp.net
page. Placed on it a Button and a TextBox. Added a reference to my
webservice.
And under the Button click handler I wrote:
'-----------------------------------------------
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub ButtonLoadFile_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ButtonLoadFile.Click
Dim MyReportServices As New localhost.MyReportServices
With MyReportServices
Response.Write(.GetReportByName(Me.TextBoxFileName.Text))
End With
End Sub
End Class
'-----------------------------------------------
This seems to work fine (file content appears before the button
and the textbox). Now my questions:
1. If I want to call the service from a simple html page
with just a textbox and a button form. What would the code be?
2. I want to distribute the .asmx so that anyone can use the service
on his/her own server.
In such a case it is correct to have -->
Namespace:="http://localhost/"
or what should it be in order to work independently of the server
where the service is
hosted?
3. I see that the response appears before the button and TextBox.
How would I change the code to make it appear past them?
Please do advice if you see I am not doing things in a right manner.
-Pam