Solved

SOAP Request build with PHP

Posted on 2014-10-16
10
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 58

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 58

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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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 58

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 58

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

617 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