The last time I talked about the successful communication between php and wcf, and the data obtained at the time was base-type data. Today I want to talk about returning object data. first, we will return a single object server. I have set a GetUser interface to return a UserInfo object publicclassUserInfo {[DataMember] publicStringName {set; ge
The last time I talked about the successful communication between php and wcf, and the data obtained at the time was base-type data. Today I want to talk about returning object data. first, we will return a single object server. I have set a GetUser interface to return a UserInfo object public class UserInfo {[DataMember] public String Name {set; ge
The last time I talked about the successful communication between php and wcf and the data obtained
The data isBase typeData
What I want to say today is to returnObject Data.
First, we will return a single object.
Server, I have set a GetUser interface to return a UserInfo object
Public class UserInfo
{
[DataMember]
Public String Name {set; get ;}
[DataMember]
Public int Age {set; get ;}
}
Serivce interface:
[OperationContract]
UserInfo GetUser ();
Php code:
$ Soap = new SoapClient ("http: // localhost: 4625/Service1.svc? Wsdl ");
$ Result = $ soap-> GetUser ();
Echo var_export ($ result-> GetUserResult-> Name); // obtain the Name attribute bird.
Echo var_export ($ result-> GetUserResult)// View the source code for this output:
StdClass ::__ set_state (array (
'Age' => 17,
'Name' => 'shuai taobao ',
))
When you look at it together, you will understand the bird
Similarly, if the interface returnsList It's easy.
Wcf Interface
[OperationContract]
List GetUsers ();
Php receiving code
$ Result = $ soap-> GetUsers ();
Echo var_export ($ result-> GetUsersResult-> UserInfo );
// Output file of the preceding sentence:
Array (0 => stdClass ::__ set_state (array ('age' => 18, 'name' => 'may',), 1 => stdClass :: __set_state (array ('age' => 20, 'name' => 'jonn ',)),)
// View the source code as follows:
Array (
0 =>
StdClass ::__ set_state (array (
'Age' => 18,
'Name' => 'may ',
)),
1 =>
StdClass ::__ set_state (array (
'Age' => 20,
'Name' => 'jonn ',
)),
)
Similarly, for example, we want to get the data Name: Jonn Age: 20.
Echo var_export ($ result-> GetUsersResult-> UserInfo [1]-> Name );
Var_dump -- print information about a variable
Description
Void var_dump (mixed expression [, mixed expression [,...])
This function displays the structure information about one or more expressions, including the expression type and value. The array recursively expands the value and displays its structure through indentation.
Var_export -- string representation of the output or returned variable
This function returns the structure information about the variables passed to this function. It is similar to var_dump (). The difference is that the returned representation is legal PHP code.