3

I have a running web service (using EclipseLink as JPA provider) and would like to call the methods that updates data in the database from PHP using SOAP.

A method in the web service may look something like this:

public void updatePerson(Person p){
   EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersonLib");
   EntityManager em = emf.createEntityManager();
   if(!em.getTransaction().isActive()) {
      em.getTransaction().begin();
   }
   em.merge(p);
   em.getTransaction().commit();
}

From PHP, I guess I have to create an object of type stdClass and send it as the parameter for a Person. Am I right? But I don´t get it work with these lines of code:

$client = new SoapClient("url.to.wsdl", array("trace" => 1));
$obj = new stdClass();
$obj->Person = new stdClass(); 
$obj->Person->personId = 1;
$obj->Person->name = "Peter";
$client->updatePerson($obj);

I don´t know if this is the correct way to send an object from PHP to Java (well, it calls the method updatePerson(Person p) in the java application, but p doesn´t contain the data I entered in PHP).

1
  • Can you show us your WSDL? Also you might want to check the examples here where the option "classmap" is used in the SoapClient constructor. Commented Feb 25, 2012 at 18:12

1 Answer 1

3

if it's possible please show us the WSDL file.

Usually when I work with SoapClient in PHP I use arrays even if the web service expects an object, so, instead of creating a new stdClass try sending the following array:

$client = new SoapClient("url.to.wsdl");
$obj    = new array("personId" => 1, "name" => "Peter");

$client->updatePerson($obj);

And that should send the object with the required data.

Hope it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

I got it working some days ago. But I did´t no I could send an array instead of objects of type stdClass! :-) Thank you for that!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.