title: nusoap send key/value pairs to MS web service
body: <p>A web service has been written by a third party to link my PHP CMS to a MS Dynamics CRM. This is a web service that I have to use (the default SOAP and REST APIs that come with Dynamics is not something we are allowed to use). I am having difficulties working out how to pass a record of name/value pairs to one of the web service functions.</p>
  
  <p>We are using nusoap to talk to the web service, as we have more chance of "fixing" the SOAP handling to talk nicely with the MS code, than if we were at the mercy of what SOAP handling PHP provides.</p>
  
  <p>I don't know much about ASP, but the function in question is defined [roughly] like this:</p>
  
  <pre><code>public class UserWebservice : System.Web.Services.WebService
  {
      public DataSet UpdateContactAddress(string ContactId, List&lt;KeyValuePair&lt;string, string&gt;&gt; Address)
      {
          ...
      }
  }
  </code></pre>
  
  <p>I can pass in the ContactId, but then have an associative array of address parts ('city'=>'My City' etc) to pass into the Address parameter. I cannot work out how to do that. If I knew what XML the web service was expecting to receive, then I could work backwards from there, but the structure is just an unknown to me.</p>
  
  <p>The web service developer can only tell me it is "the standard" format, whatever that means.</p>
  
  <p>In case it helps, this is how the UpdateContactAddress processes the parameter:</p>
  
  <pre><code>Entity contact = new Entity("contact");
  contact.Id = new Guid(ContactId);
  foreach (KeyValuePair&lt;string, string&gt; AddressPart in Address)
  {
      contact[AddressPart.Key] = AddressPart.Value;
  }
  </code></pre>
  
  <p>If there is a better data type to use for the web service to accept a record of name/value pairs, then I could probably argue the case for it to be changed.</p>
  
  <p>It would be nice to think that using a WSDL means all this "just works", but I accept it won't (PHP&lt;--&gt;MS: haha!) and am building the elements manually in parameters passed to nusoap (nesting soap_val objects and arrays as needed, which works for simple arrays of values).</p>
  
  <hr>
  
  <p>Edit:<br>
  Just to add to one of that latter points about changing the datatype, if something like this, assuming it is syntactically correct, will be easier to handle, then I would go along with that:</p>
  
  <pre><code>KeyValuePair&lt;string, string&gt;[] Address
  </code></pre>
  
  <p>i.e. a simple numeric-keyed array of "name-value pairs", which I understand is not as simple as a key/value array element in PHP. Passing in simple arrays to the MS web service works for me, so removing the unknowns is a good move. The problem  here is no debug activity on the MS side - they get the data or they don't, and if they don't, it is my fault for not passing it right but there are no clues what "right" actually is. I'm hoping somebody here has done this and got it working, and can point me in the right direction.</p>