Udostępnij za pośrednictwem


Web Services Quiz: Issue 2

Do you see a problem in the following Web Service implementation?

My opinion about this code snippet will follow…

namespace Issue2

{

public class DeletePersonRequest

{

public string name;

public string firstname;

// place holder to carry unknown elements

[XmlAnyElement]

public XmlElement[] Any;

}

[WebService(Namespace="uri.beatsch.Issue2")]

public class Issue2 : System.Web.Services.WebService

{

[WebMethod]

[SoapDocumentMethod(OneWay=true, ParameterStyle=SoapParameterStyle.Bare)]

public void DeletePerson(DeletePersonRequest dpr)

{

// Just do something

return;

}

}

}

Comments

  • Anonymous
    February 25, 2004
    Problem creating the proxy class?
  • Anonymous
    February 26, 2004
    Maybe not asyncronous friendly? Deleting a person with a one-way call without any return might not be the best solution...

    Maybe sending a class with the parameter style of being bare might be an issue to. Makes more sense for it to be wrapped considering you are passing ONE object into the method...


  • Anonymous
    February 26, 2004
    Jake,

    You’re absolutely right with the first point, the one-way stuff. I’ll comment on that in the answer to the quiz.

    But in your second comment, you mixed the two parameter styles:
    Bare means, no wrapper will be generated, where the wrapped style automatically generates a wrapper type containing the different arguments as elements. Let’s look at the two soap bodies:

    Bare:
    <soap:Body>
    <dpr xmlns="uri.beatsch.Issue2">
    <name>Beat</name>
    <firstname>Schwegler</firstname>
    </dpr>
    </soap:Body>

    Wrapped:
    <soap:Body>
    <DeletePerson xmlns="uri.beatsch.Issue2">
    <dpr>
    <name>Beat</name>
    <firstname>Schwegler</firstname>
    </dpr>
    </DeletePerson>
    </soap:Body>

    Therefore, using bare in our message based example is absolutely the right way to go.
  • Anonymous
    February 26, 2004
    I really wanted to poke at the use of the XmlAnyElement.. but as I kept looking it over, I don't see how obvious the problem with that would be..

    Thanks for the clarification of the wrapper, i'm not wise in the ways of Web Services just yet and it's always nice to learn...

    The reason I wanted to use the wrapper would be in case the excess data matched another object, thus sending two objects and potentially injecting another deletion.. if you had a wrapper you could treat it as only one object. Am I making any sense? (Considering my second statment :) )

    Jake
  • Anonymous
    February 26, 2004
    I understand what you mean, but since we’re only interested in known elements this won’t cause trouble. Therefore we extract only name and firstname:

    public void DeletePerson(DeletePersonRequest dpr)
    {
    string name = dpr.name;
    string firstname = dpr.firstname;


    // do something
    }