Wrox Programmer Forums
|
ASP E-commerce As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP E-commerce section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 30th, 2004, 03:31 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default Web Service Code

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







Similar Threads
Thread Thread Starter Forum Replies Last Post
Web Service Consuming another web service CraigWhitfield EJB 0 January 10th, 2008 08:38 AM
web service ajaytiwarilic ASP.NET 2.0 Basics 0 February 24th, 2007 10:40 AM
Error to Add Web Reference from a Web service jdjbarrios ASP.NET 2.0 Professional 0 July 18th, 2006 02:58 PM
Need help with a web service Dsypher C# 2005 1 January 2nd, 2006 04:27 PM
Service Oriented Web Service aldwinenriquez .NET Web Services 2 September 15th, 2005 03:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.