Kirk Evans Blog

.NET From a Markup Perspective

ASMX HelloWorld As It Ought To Be

@kaevans

ASMX HelloWorld As It Ought To Be

  • Comments 3

You're right, Christian... HelloWorld should look a lot different.  Assuming it should be HelloWorld at all (Indigo templates so far name it MyOperation1), here is a little change to your proposed HelloWorld:

IWebService.cs:

using System.Xml;
using System.Xml.Serialization;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1, EmitConformanceClaims = true)]
[WebService(Name = "WebService", Namespace = "urn:thinktecture-com:demos:webservices:2004:v1")]
public interface IWebService
{
    [WebMethod]
    [return: XmlElement(ElementName = "HelloResponseMessage")]
    [SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)]
    HelloResp HelloWorld([XmlElement(ElementName = "HelloRequestMessage")]HelloReq req);
}

WebService.cs:

using System;

public class WebService : IWebService
{
    #region IWebService Members

    public HelloResp HelloWorld(HelloReq req)
    {
        HelloResp resp = new HelloResp();
        resp.Hello = "Hello again ...";

        return resp;
    }

    #endregion
}

Messages.cs:

using System;
using System.Xml.Serialization;


[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;
}

 

  • I did a presentation on ASMX 2.0 in the Atlanta office that showed off designing services using interfaces. ...
Page 1 of 1 (3 items)
Leave a Comment
  • Please add 2 and 3 and type the answer here:
  • Post
Translate This Page
Search
Archive
Archives