I'm using JavaScript to communicate to a WCF service via XML (I can't use JSON). This has been working well so far for WCF methods which expose arguments of "primitive" data types, but now I need to call a WCF method which accepts an array. I've been unable to figure out how to tweak my XML properly.
For example, a WCF method with two parameters accepts:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<MySimpleMethod xmlns="http://tempuri.org/">
<parameter1>value</parameter1>
<parameter2>someOtherValue</parameter2>
</MySimpleMethod>
</s:Body>
</s:Envelope>
I thought I might be able to pass an array (of strings in this case) by doing the following:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<MyMethodWithAnArrayParameter xmlns="http://tempuri.org/">
<arrayParameterName>value1</arrayParameterName>
<arrayParameterName>value2</arrayParameterName>
</MyMethodWithAnArrayParameter>
</s:Body>
</s:Envelope>
But this hasn't worked. If anyone has any insight I'd be very appreciative.
Thanks.
EDIT:
Making progress. Darin's answer works for primitive data types, but I'm unable to pass something more complex, say an array of the following class:
public class Address
{
public String Number {get; set;};
public String City {get; set;};
public String State {get; set;};
}
I've tried this:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<TestMethod xmlns="http://tempuri.org/">
<args xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Address>
<Number>31</Number>
<City>Houston</City>
<State>Texas</State>
</a:Address>
</args>
</TestMethod>
</s:Body>
</s:Envelope>
The method gets called (I can verify this in a debugger), but the array that it gets passed is empty.
Assuming the following method signature exposed over a
basicHttpBinding
:you could invoke like this:
UPDATE:
Assuming the following operation contract:
The request could look like this