I wrote Web Service code in
VB.Net but when add web reference to Web Service from a Web form the code looks different. Look below. Is this suppose to look different?
Also when I tested the Web service by type
http://localhost/ASP.NET/Chapter_16/...DaysUntil.asmx in the browser it works fine.
But when I create an instance of the Web service I get an error.
Is this because the code generated when create a web referrence different?
[u]
Actual Web service which works:</u>
Imports System.Web.Services
<System.Web.Services.WebService(Namespace:="http ://m.com", _
Description:="Calculates the number of days until a given date")> _
Public Class DaysUntil
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function DaysUntil(ByVal [Date] As Date) As Integer
Return DaysUntilDate([Date].Month, [Date].Day)
End Function
<WebMethod()> _
Public Function DaysUntilHalloween() As Integer
Return DaysUntilDate(10, 31)
End Function
<WebMethod()> _
Public Function DaysUntilChristmas() As Integer
Return DaysUntilDate(12, 25)
End Function
Private Function DaysUntilDate(ByVal month As Integer, ByVal day As Integer)
Dim TargetDate As DateTime
TargetDate = DateTime.Parse(month.ToString & "/" & _
day.ToString & "/" & Now.Year)
If Today > TargetDate Then
TargetDate = TargetDate.AddYears(1)
End If
Return DateDiff(DateInterval.Day, Today, TargetDate)
End Function
End Class
[u]
Code of Instance of Web service:</u>
Option Explicit On
Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization
'
'This source code was auto-generated by Microsoft.VSDesigner, Version 1.1.4322.573.
'
Namespace localhost
<System.Diagnostics.DebuggerStepThroughAttribute() , _
System.ComponentModel.DesignerCategoryAttribute("c ode"), _
System.Web.Services.WebServiceBindingAttribute(Nam e:="DaysUntilSoap", [Namespace]:="http://m.com")> _
Public Class DaysUntil
Inherits System.Web.Services.Protocols.SoapHttpClientProtoc ol
Public Sub New()
MyBase.New
Me.Url = "http://localhost/ASP.NET/Chapter_16/DaysUntil/DaysUntil.asmx"
End Sub
<System.Web.Services.Protocols.SoapDocumentMethodA ttribute("http://m.com/DaysUntil", RequestNamespace:="http://m.com", ResponseNamespace:="http://m.com", Use:=System.Web.Services.Description.SoapBindingUs e.Literal, ParameterStyle:=System.Web.Services.Protocols.Soap ParameterStyle.Wrapped)> _
Public Function DaysUntil(ByVal [Date] As Date) As Integer
Dim results() As Object = Me.Invoke("DaysUntil", New Object() {[Date]})
Return CType(results(0),Integer)
End Function
Public Function BeginDaysUntil(ByVal [Date] As Date, ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("DaysUntil", New Object() {[Date]}, callback, asyncState)
End Function
Public Function EndDaysUntil(ByVal asyncResult As System.IAsyncResult) As Integer
Dim results() As Object = Me.EndInvoke(asyncResult)
Return CType(results(0),Integer)
End Function
<System.Web.Services.Protocols.SoapDocumentMethodA ttribute("http://m.com/DaysUntilHalloween", RequestNamespace:="http://m.com", ResponseNamespace:="http://m.com", Use:=System.Web.Services.Description.SoapBindingUs e.Literal, ParameterStyle:=System.Web.Services.Protocols.Soap ParameterStyle.Wrapped)> _
Public Function DaysUntilHalloween() As Integer
Dim results() As Object = Me.Invoke("DaysUntilHalloween", New Object(-1) {})
Return CType(results(0),Integer)
End Function
Public Function BeginDaysUntilHalloween(ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("DaysUntilHalloween", New Object(-1) {}, callback, asyncState)
End Function
Public Function EndDaysUntilHalloween(ByVal asyncResult As System.IAsyncResult) As Integer
Dim results() As Object = Me.EndInvoke(asyncResult)
Return CType(results(0),Integer)
End Function
<System.Web.Services.Protocols.SoapDocumentMethodA ttribute("http://m.com/DaysUntilChristmas", RequestNamespace:="http://m.com", ResponseNamespace:="http://m.com", Use:=System.Web.Services.Description.SoapBindingUs e.Literal, ParameterStyle:=System.Web.Services.Protocols.Soap ParameterStyle.Wrapped)> _
Public Function DaysUntilChristmas() As Integer
Dim results() As Object = Me.Invoke("DaysUntilChristmas", New Object(-1) {})
Return CType(results(0),Integer)
End Function
Public Function BeginDaysUntilChristmas(ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke("DaysUntilChristmas", New Object(-1) {}, callback, asyncState)
End Function
Public Function EndDaysUntilChristmas(ByVal asyncResult As System.IAsyncResult) As Integer
Dim results() As Object = Me.EndInvoke(asyncResult)
Return CType(results(0),Integer)
End Function
End Class
End Namespace