search
Homephp教程php手册PHP与WCF通信数据获取

上回说到php与wcf成功通信了,并且得到了数据 当时说的数据是 基类型 数据 今天我要说的是返回 对象数据 . 首先我们说返回单个对象 服务端,我定了一个GetUser的接口,返回一个UserInfo对象 public class UserInfo { [DataMember] public String Name { set; ge

上回说到php与wcf成功通信了,并且得到了数据
当时说的数据是基类型数据
今天我要说的是返回对象数据.
首先我们说返回单个对象
服务端,我定了一个GetUser的接口,返回一个UserInfo对象
public class UserInfo
{
[DataMember]
public String Name { set; get; }
[DataMember]
public int Age { set; get; }
}
Serivce接口:
[OperationContract]
UserInfo GetUser();
Php代码:
$soap=new SoapClient("http://localhost:4625/Service1.svc?wsdl");
$result=$soap->GetUser();
echo var_export($result->GetUserResult->Name);//得到Name属性鸟

echo var_export($result->GetUserResult)//这句输出查看源码如下
stdClass::__set_state(array(
'Age' => 17,
'Name' => '帅呆',
))
结合着看,你就明白鸟


同理,如果接口返回一个List也简单了

wcf接口
[OperationContract]
List GetUsers();
Php接收代码
$result=$soap->GetUsers();
echo var_export($result->GetUsersResult->UserInfo);
//以上这句输出文件:
array ( 0 => stdClass::__set_state(array( 'Age' => 18, 'Name' => 'May', )), 1 => stdClass::__set_state(array( 'Age' => 20, 'Name' => 'Jonn', )), )
//查看源码如下
array (
0 =>
stdClass::__set_state(array(
'Age' => 18,
'Name' => 'May',
)),
1 =>
stdClass::__set_state(array(
'Age' => 20,
'Name' => 'Jonn',
)),
)
同样,比如我们现在欲得到Name:Jonn Age:20这个数据
echo var_export($result->GetUsersResult->UserInfo[1]->Name);


var_dump -- 打印变量的相关信息
描述
void var_dump ( mixed expression [, mixed expression [, ...]] )
此函数显示关于一个或多个表达式的结构信息,包括表达式的类型与值。数组将递归展开值,通过缩进显示其结构

var_export -- 输出或返回一个变量的字符串表示
此函数返回关于传递给该函数的变量的结构信息,它和 var_dump() 类似,不同的是其返回的表示是合法的 PHP 代码。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)