This post originated from an RSS feed registered with .NET Buzz
by Christian Weyer.
Original Post: ASMX's 'HelloWorld' as it is supposed to be - VS team look!
Feed Title: Christian Weyer: Web Services & .NET
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/cweyer/Rss.aspx
Feed Description: Philosophizing about and criticizing the brave new world ...
Sorry, I have a request. These days, I am thinking a lot about contract-first design and development of Web services. If we cannot get a nice graphical contract editor, then we at least could try to model our .NET-based code to hammer down an actual contract and decouple the internal .NET implementation from this message and interface contract notation. You may want to call this 'code-based contract-first' versus 'schema-based contract-first'. Anyway ...
Hopefully the Visual Studio 2005 team will change the default code template for the still too simple and misleading Web Services wizard in Beta 1. And ... what about the coding style with curly braces at the end of the line? The current Beta of VS 2005 generates ugly code, IMO.
So here is my suggestion of what Visual Studio should actually generate - in order to propagate the message-based nature of Web services (all other VS-necessary code and comments stuff ommitted ...):
HelloService.asmx.cs:
[WebService(Namespace="urn:thinktecture-com:demos:webservices:2004:v1")] [SoapDocumentService(ParameterStyle=SoapParameterStyle.Bare)] public class HelloService : System.Web.Services.WebService { [WebMethod] [return: XmlElement(ElementName="HelloResponseMessage")] public HelloResp HelloWorld([XmlElement(ElementName="HelloRequestMessage")]HelloReq req) { HelloResp resp = new HelloResp(); resp.Hello = "Hello again ...";
return resp; } }
Messages.cs:
[XmlType(TypeName="HelloRequest", Namespace="urn:thinktecture-com:demos:webservices:messages:v1")] public class HelloReq { }
[XmlType(TypeName="HelloResponse", Namespace="urn:thinktecture-com:demos:webservices:messages:v1")] public class HelloResp { [XmlElement(ElementName="Hello")] public string Hello; }
Hope this makes sense ... well, of course we could discuss whether it really has to be a classical 'Hello World' thingie at all ...