Re: publishing Hello World to local IIS



I understand now. "Decorate" means to beautify to me and I was at a loss as to how that worked with web services. I was thinking it formatted the page pulled up by http://localhost/service1.asmx, like changing the colors etc.



Steven Cheng[MSFT] wrote:
Hi Cj,

The "WebMethodAttribute" I mentioned is used to indicate that a certain class method of the webservice class should be exposed as "webmethod"(which can be called by client proxy as webservice method). Here is a typical HelloWorld webservice:

================
<WebService(Namespace:="http://tempuri.org/";)> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class simpleservice
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function

End Class
=================

in VB.NET the syntax for applying attribute is <WebMethod()> _

Therefore, to summarize, "<WebService>" is used at class level while <WebMethod> is used at function level, they're both used to decorate a webservice class.

Does this clarify a bit?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
Date: Tue, 15 Jan 2008 11:33:44 -0500
From: cj <cj@xxxxxxxxxxxxx>
User-Agent: Thunderbird 2.0.0.6 (Windows/20070728)
MIME-Version: 1.0
Subject: Re: publishing Hello World to local IIS


I'm sorry but what do you mean by:

Also, for each WebService method in it, you need to decorate it with
<WebMethodAttribute>

Can you give me an example of where I would add that? Am I right in that it is needed for remote access to the web service?

<System.Web.Services.WebService(Name:="CJ's Service", Description:="Testing 123")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1
_1)> _
<ToolboxItem(False)> _
Public Class Service1

Steven Cheng[MSFT] wrote:
Hi Cj,

Yes, you should keep one webservice class in each asmx. Also, you can
add
more than one classes in an asmx file(codebehind), however, the key point is that only one of them should be marked as a "WebService", this is done through the "WebServiceAttrribute"(the <WebService(....)> in VB.NET). e.g.

<WebService("Name=.....")>
public class ServiceClass
{

}

Also, for each WebService method in it, you need to decorate it with <WebMethodAttribute>

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no
rights.
--------------------
Date: Mon, 14 Jan 2008 17:01:06 -0500
From: cj <cj@xxxxxxxxxxxxx>
Subject: Re: publishing Hello World to local IIS

If I create a second class inside Service1.asmx it doesn't show in http://localhost/Service1.asmx. I take it that is normal. I guess I'm only allowed 1 class inside service1.asmx that will show and that class must be named service1.asmx. Is this correct?

For instance in the below code http://localhost/Service1.asmx doesn't show any of the Goodbye services. It does show HelloWorld and HelloCJ.

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/";)> _

<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1
_1)> _
<ToolboxItem(False)> _
Public Class Service1
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function

<WebMethod()> _
Public Function HelloCJ() As String
Return "Hello CJ"
End Function
End Class

<System.Web.Services.WebService(Namespace:="http://tempuri.org/";)> _

<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1
_1)> _
<ToolboxItem(False)> _
Public Class Service2
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function GoodbyeWorld() As String
Return "Goodbye World"
End Function

<WebMethod()> _
Public Function GoodbyeCJ() As String
Return "Goodbye CJ"
End Function
End Class



But even if I create a new service Service2.asmx inside the project and put the goodbye code in it I can't get http://localhost/Service2.asmx to bring up anything. I would have thought that would work.



Steven Cheng[MSFT] wrote:
Hi Cj,

Glad that you've got progress. As for providing multiple webservices, I think it is up to you that how to arrange those webservice methods/endpoints.

If you have many service functions that belong to the same business
logic,
you may group them in the same asmx service endpoint. Otherwise, you can separate them into multiple webservice asmx endpoint. And you can create separate webservice proxy classes for them.

In addition, if you want to make your client consumers easy to visit and consume your service, I suggest you create a dedicated aspx web page
which
grou p all the service's description page (...asmx?wsdl) on it (as hyperlink). Thus, your clients can just visit that page and lookup all
the
services you provided.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no
rights.
--------------------
Date: Thu, 10 Jan 2008 11:14:15 -0500
From: cj <cj@xxxxxxxxxxxxx>
User-Agent: Thunderbird 2.0.0.6 (Windows/20070728)
MIME-Version: 1.0
Subject: Re: publishing Hello World to local IIS


I got time this AM to look at this some more. My project is named MyTestWebService1 and saved it to the default web site on the local IIS. The WebMethod is HelloWorld. I was kind of surprised I had to type http://localhost/Service1.asmx into the browser. It did then show me that HelloWorld was there and I could test it.

I guess my question is if I want to make a couple of web services should I add another .asmx file to the project? Or should I add another WebMethod to Service1.asmx? Or should I start a new project for the second web service?

How is this generally done? I want to do it as simply as possible but also would like to do it the way most people are used to using them.

Eventually we have a couple business partners that will need to use the web services and I want it to be easy for them to use.

Thanks for your help.


Steven Cheng[MSFT] wrote:

.



Relevant Pages

  • Re: Self running timer on Webservice??
    ... > Web services are stateless - so a call to one method won't carry over to ... I would like to start a webservice that copies that file each 24 hours ... >>Public Function StartTimer() As String ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: publishing Hello World to local IIS
    ... \par Here are some general reference about the webservice essentials(most of them are of XML webservice standard, not platform coupled concepts) which may help you better understand webservice: ... \par loss as to how that worked with web services. ... \par> Public Function HelloWorld() As String ... \par>> Public Class Service1 ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: WebService - XML
    ... MVP Scott Mitchell provides all the details you'll need to find your answer ... > how to send the soap-xml, but not how to get the webservice to work ... > Public Class Service1 ... > Public Function Add ...
    (microsoft.public.dotnet.framework.aspnet)
  • WebService - XML
    ... How do I change my webservice, ... how to send the soap-xml, but not how to get the webservice to work ... Public Class Service1 ... Public Function Add ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: use SOAP header for asp.net session state
    ... We are creating web services for our customer to get data in and out of the system. ... HttpWebRequest class to send/receive webservice request/response SOAP ... cookie returned from server-side ASP.NET webservice. ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.dotnet.framework.aspnet.webservices)