views:

440

answers:

4

Hi all

We are trying to create a web-service that we plan to pass a variable amount of variables to it.

Can this be done?

Basically instead of pass all possible parameters we wish to pass only the set values and use the defaults set in the web-service.

Here is an example of the XML we are looking to send, we would sent an unknown amount of functions depending on the needed return.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  <soap:Body>
    <WebMethod xmlns="http://tempuri.org/"&gt;
      <domains>
        <function1>
     <title>Some Title</title>
     <type>25</type>
        </function1>
    <function2 />
    <function3>
     <param>13</param>
    </function3>
      </domains>
    </WebMethod>
  </soap:Body>
</soap:Envelope>

Will this work or should we do a different way?

Paul

A: 

You can simply pass a variable-length array as a parameter.

Konrad Rudolph
A: 

If you dont like the idea of an Array (this is not slating Konrad's answer - you may have differing param types) you can pass complex objects (i.e. objects that you made yourself).. The downside is that you cannot then test using the ASMX page, but would need to do it all in code (which isn't really a bad thing, especially if you are used to it).

Rob Cooper
+3  A: 

I would pass in an xml document instead of doing concreate functions for this.

The webservice in your example is leaky - the consumer needs to know too much about this interface and the implementation of the webservice internally.

XML Document and then tie that with an XSD. That way you can prevalidte the input to the webservice.

Take a look at these

IBM Developer ASP.NET Forum

I would also recommend using this for testing webservices and its free WSStudio

A: 

I agree with littlegeek. Do not make your web service is hard method. Make it a receiving end point to receive messages. Particularly, a Command Message.

http://www.eaipatterns.com/CommandMessage.html

icelava