Problem passing an array containing complex d

Help
chris
2008-08-14
2013-06-06
  • chris
    chris
    2008-08-14

    Hello there!

    NuSOAP is currently giving me a bit of a headache, maybe someone here can help me out.

    I'm using NuSOAP for a PHP client to an ASP.NET web service. For a few methods, I have to pass complex data structures. Here is an excerpt of the types in the WSDL file:

    Code:

          <s:complexType name="Job">
            <s:sequence>
              <s:element minOccurs="0" maxOccurs="1" name="Field1" type="s:string"/>
              <s:element minOccurs="0" maxOccurs="1" name="Field2" type="s:string"/>
              <s:element minOccurs="1" maxOccurs="1" name="Field3" type="s:int"/>
              <s:element minOccurs="0" maxOccurs="1" name="Mutationen" type="tns:ArrayOfMutation"/>
            </s:sequence>
          </s:complexType>
          <s:complexType name="ArrayOfMutation">
            <s:sequence>
              <s:element minOccurs="0" maxOccurs="unbounded" name="Mutation" nillable="true" type="tns:Mutation"/>
            </s:sequence>
          </s:complexType>
          <s:complexType name="Mutation">
            <s:sequence>
              <s:element minOccurs="0" maxOccurs="1" name="Name" type="s:string"/>
              <s:element minOccurs="0" maxOccurs="1" name="JobParams" type="tns:ArrayOfJobParam"/>
            </s:sequence>
          </s:complexType>
          <s:complexType name="ArrayOfJobParam">
            <s:sequence>
              <s:element minOccurs="0" maxOccurs="unbounded" name="JobParam" nillable="true" type="tns:JobParam"/>
            </s:sequence>
          </s:complexType>
          <s:complexType name="JobParam">
            <s:sequence>
              <s:element minOccurs="1" maxOccurs="1" name="JobParamId" type="s:int"/>
              <s:element minOccurs="0" maxOccurs="1" name="Value" type="s:string"/>
            </s:sequence>
          </s:complexType>

    The web service method takes an object of the type "Job" as parameter. I'm calling the method like this:

    Code:

    $job = array(
      "Name" => "Foobar",
      "Field1" => 42,
      "Field2" => "x",
      "Mutationen" => array (
        "Mutation" => array (
          "Name" => "Foobar",
          "JobParams" => array (
            array("JobParamId" => 1, "Value" => "foo"),
            array("JobParamId" => 2, "Value" => "bar"),
            array("JobParamId" => 3, "Value" => "42"),
            array("JobParamId" => 4, "Value" => "23")
          )
        )
      )
    );

    $nusoap_client = new nusoap_client("http://path-to-my-wsdl-file", "wsdl");
    $nusoap_client->call("MyMethod", $job, "","", false, true);

    However, the elements of the "JobParams" array are not passed to the web service. The reason seems to be that NuSOAP expects the keys of each element of that array to be "JobParam", like the name of the respective type in the WSDL file. If the array contains only one entry with the key "JobParam", it works. But obviously, this doesn't do for me, since I have to pass multiple "JobParam" objects/arrays, and a PHP array can't have the same key multiple times, as we all know. The code below would work, but wouldn't serve me well:

    Code:

    $job = array(
      "Name" => "Foobar",
      "Field1" => 42,
      "Field2" => "x",
      "Mutationen" => array (
        "Mutation" => array (
          "Name" => "Foobar",
          "JobParams" => array (
            "JobParam" => array("JobParamId" => 1, "Value" => "foo")
          )
        )
      )
    );

    $nusoap_client = new nusoap_client("http://path-to-my-wsdl-file", "wsdl");
    $nusoap_client->call("MyMethod", $job, "","", false, true);

    I hope it is clear enough what my problem is, otherwise please tell me so.

    Is this a bug in NuSOAP, or am I just doing something wrong? Please help me, I'm on a deadline, and I'm completely stuck!

    Best regards,
    Chris

     
    • chris
      chris
      2008-08-14

      Just to let you know, I just figured it out myself. I wonder why I haven't tried this yet. The code is very counter-intuitive, but at least now it works:

      Code:

      $job = array(
        "Name" => "Foobar",
        "Field1" => 42,
        "Field2" => "x",
        "Mutationen" => array (
          "Mutation" => array (
            "Name" => "Foobar",
            "JobParams" => array("JobParam" => array (
              array("JobParamId" => 1, "Value" => "foo"),
              array("JobParamId" => 2, "Value" => "bar"),
              array("JobParamId" => 3, "Value" => "42"),
              array("JobParamId" => 4, "Value" => "23")
            ))
          )
        )
      );

      $nusoap_client = new nusoap_client("http://path-to-my-wsdl-file", "wsdl");
      $nusoap_client->call("MyMethod", $job, "","", false, true);