PHP and WCF Communication Data Acquisition

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.