Christian Weyer: Smells like service spirit

What's first?

ASMX's 'HelloWorld' as it is supposed to be - VS team look!

[Update: I forgot an important attribute - which is responsible for Whidbey's BP 1.0 compliance]

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:

[WebServiceBinding(ConformanceClaims=WsiClaims.BP10, EmitConformanceClaims=true)]
[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 ...

Comments

No Comments