Solved

SOAP Request build with PHP

Posted on 2014-10-16
10
261 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 51

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 51

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
 

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 51

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 51

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now