Solved

SOAP Request build with PHP

Posted on 2014-10-16
10
265 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 54

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 54

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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 54

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 54

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use embargo Date/time in php 29 39
Redirecting an Outlook attachment to a specific folder? 3 49
Powershell File Sort 8 31
parse url to form? 6 10
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

809 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