Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SOAP Request build with PHP

Posted on 2014-10-16
10
Medium Priority
?
278 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 59

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 59

Accepted Solution

by:
Julian Hansen earned 1500 total points
ID: 40396233
Sounds like you will need to create an array of objects - if the SOAP calling mechanism supports that.
0
Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

 

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 59

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 59

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

722 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