Solved

SOAP Request build with PHP

Posted on 2014-10-16
10
267 Views
Last Modified: 2016-02-26
Hi Guys,

I have .net service which needs to be connected via PHP. the sample SOAP envelop is below
 
<?xml version="1.0" encoding="UTF-8"?>
<ObjectActionRequest xmlns="http://www.something.com/types/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <Action>Create</Action>
  <ObjectInstanceId>0</ObjectInstanceId>
  <RequestId>ac6a002d-2c59-45f7-bd26-bba2bd5c23fb</RequestId>
    <AttributeSets>
      <AttributeSetDto>
        <Attributes>
          <AttributeDto>
            <AttributeId>3020</AttributeId>
            <AttributeInstanceId>0</AttributeInstanceId>
            <AttributeSetId>4</AttributeSetId>
            <DataType i:nil="true" />
            <DisplayText i:nil="true" />
            <Editable>false</Editable>
            <FieldName i:nil="true" />
            <HookRoutine xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" i:nil="true" />
            <InputMask i:nil="true" />
            <Mandatory>false</Mandatory>
            <Name i:nil="true" />
            <OriginalValue i:nil="true" />
            <PPVisible>false</PPVisible>
            <Value xmlns:a="http://www.w3.org/2001/XMLSchema" i:type="a:string">47</Value>
          </AttributeDto>
          <AttributeDto>
            <AttributeId>3021</AttributeId>
            <AttributeInstanceId>0</AttributeInstanceId>
            <AttributeSetId>4</AttributeSetId>
            <DataType i:nil="true" />
            <DisplayText i:nil="true" />
            <Editable>false</Editable>
            <FieldName i:nil="true" />
            <HookRoutine xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" i:nil="true" />
            <InputMask i:nil="true" />
            <Mandatory>false</Mandatory>
            <Name i:nil="true" />
            <OriginalValue i:nil="true" />
            <PPVisible>false</PPVisible>
            <Value xmlns:a="http://www.w3.org/2001/XMLSchema" i:type="a:string">67</Value>
          </AttributeDto>
        </Attributes>
      <ObjectId>0</ObjectId>
    <ObjectInstId>0</ObjectInstId>
    <SetId>4</SetId>
  </AttributeSetDto>
</AttributeSets>
   <Filter i:nil="true" />
   <ObjectType>
    <DataType>2</DataType>
   </ObjectType>
</ObjectActionRequest>

Open in new window

I need to pass multiple attribures to finish the request.
I got below code working which allows me to pass one attribute at a time. I am not sure how can i pass multiple attributes in one request so it generates similar envelop as above.

below is my sample php code which allows me to pass one parameter where attributeid=3020 but i also needs to pass attributeid 3021 and may be some more in future.
  $params1->request->Action = 'Create';
  $params1->request->ObjectInstanceId = 0;
  $params1->request->AttributeSets=new stdClass;
  $params1->request->AttributeSets->AttributeSetDto=new stdClass;
  $params1->request->AttributeSets->AttributeSetDto->ObjectId=0;
  $params1->request->AttributeSets->AttributeSetDto->ObjectInstId=0;
  $params1->request->AttributeSets->AttributeSetDto->SetId=4;
  $params1->request->ObjectType= new stdClass;
  $params1->request->ObjectType->DataType=2;
  $params1->request->AttributeSets->AttributeSetDto->Attributes= new stdClass;
  $params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto= new stdClass;
  $params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto= new stdClass;
  $params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto->AttributeId=3020;
  $params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto->AttributeInstanceId=0;
  $params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto->AttributeSetId=4;

  $typedVar = new SoapVar("47", XSD_STRING, "int", "http://www.w3.org/2001/XMLSchema");

  $params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto->Value = $typedVar;
  $res =  $this->ObjectAction($params1);

Open in new window

0
Comment
Question by:KearneyGroup
  • 5
  • 4
10 Comments
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 40386802
To clarify. You said

 need to pass multiple attribures to finish the request.
I got below code working which allows me to pass one attribute at a time.

What do you mean by multiple attributes - and passing one attribute at a time. Your code (PHP) seems to be setting multiple attributes or are you talking about <Attribute> elements within the XML SOAP request?

I would imagine the way to solve this would be to have an array of attributes but without seeing how the rest of your PHP code works difficult to say how to do that.
0
 

Author Comment

by:KearneyGroup
ID: 40395967
i want to pass multiple <AttributeDto> with all properties.

from line 8 to 41 is my soap sample which has multiple <AttributeDto>. i have included only 2 but there may be up to 20 <AttributeDto>

in my php code from line 10 to 15 i have passed one of the <AttributeDto> values using creating object.
0
 
LVL 55

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 40396233
Sounds like you will need to create an array of objects - if the SOAP calling mechanism supports that.
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

Author Comment

by:KearneyGroup
ID: 40398065
do you have sample code even just 2-3 lines to show me how to create array of object for soap request
0
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 40398120
Not without knowing how your code works

This line seems to pass the created object - which includes a SoapVar to the ObjectAction method - not familiar with that can you post more code?
$res =  $this->ObjectAction($params1);

Open in new window

0
 

Author Comment

by:KearneyGroup
ID: 40405444
Sorry guys for late response as i was away sick.

Above is my SOAP sample and below is my complete PHP code

$params1->request->Action = 'Create';

		$params1->request->ObjectInstanceId = 0;


		$params1->request->AttributeSets=new stdClass;

		$params1->request->AttributeSets->AttributeSetDto=new stdClass;

		$params1->request->AttributeSets->AttributeSetDto->ObjectId=0;

		$params1->request->AttributeSets->AttributeSetDto->ObjectInstId=0;


		$params1->request->AttributeSets->AttributeSetDto->SetId=4;

		$params1->request->ObjectType= new stdClass;

		$params1->request->ObjectType->DataType=2;



		$params1->request->AttributeSets->AttributeSetDto->Attributes= new stdClass;

		$params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto= new stdClass;

		$params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto= new stdClass;

		$params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto->AttributeId=3020;

		$params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto->AttributeInstanceId=0;

		$params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto->AttributeSetId=4;
		$typedVar = new SoapVar("47", XSD_STRING, "int", "http://www.w3.org/2001/XMLSchema");

		$params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto->Value = $typedVar;

		$res =  $this->ObjectAction($params1);

Open in new window

$params1->request->Action = 'Create';

            $params1->request->ObjectInstanceId = 0;


            $params1->request->AttributeSets=new stdClass;

            $params1->request->AttributeSets->AttributeSetDto=new stdClass;

            $params1->request->AttributeSets->AttributeSetDto->ObjectId=0;

            $params1->request->AttributeSets->AttributeSetDto->ObjectInstId=0;


            $params1->request->AttributeSets->AttributeSetDto->SetId=4;

            $params1->request->ObjectType= new stdClass;

            $params1->request->ObjectType->DataType=2;



            $params1->request->AttributeSets->AttributeSetDto->Attributes= new stdClass;

            $params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto= new stdClass;

            $params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto= new stdClass;

            $params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto->AttributeId=3020;

            $params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto->AttributeInstanceId=0;

            $params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto->AttributeSetId=4;
            $typedVar = new SoapVar("47", XSD_STRING, "int", "http://www.w3.org/2001/XMLSchema");

            $params1->request->AttributeSets->AttributeSetDto->Attributes->AttributeDto->Value = $typedVar;

            $res =  $this->ObjectAction($params1);
0
 

Author Comment

by:KearneyGroup
ID: 40405455
below is the c# code which i am trying to convert to PHP. it's a different soap envelope but has similar structure.

var set11 = new AttributeSetDto
{
SetId = 11,
Attributes = new List<AttributeDto> {
new AttributeDto { Value = “Sort_Name”, AttributeId = 1, AttributeSetId = 11 },
new AttributeDto { Value = "LastName", AttributeId = 715, AttributeSetId = 11 },
new AttributeDto { Value = "phone", AttributeId = 708, AttributeSetId = 11 },
new AttributeDto { Value = 42, AttributeId = 30, AttributeSetId = 11}
}
};

Open in new window

0
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 40406053
PHP code is same snippet as before - it does not tell us what this does

  $res =  $this->ObjectAction($params1); 

Open in new window


This is the key - how does the ObjecAction method deal with the $params1 parameter.
0
 

Author Comment

by:KearneyGroup
ID: 40407271
i got it working by creating array as suggested by you.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question