Reputation: 2917
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).
Upvotes: 3
Views: 5460
Reputation: 808
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.
Upvotes: 3