Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 知道服务器端Wsdl,不写服务端代码,仅写客户端代码能调用服务端的方法吗?

知道服务器端Wsdl,不写服务端代码,仅写客户端代码能调用服务端的方法吗?

Jun 23, 2016 pm 02:13 PM

新手请教,望高手朋友不吝赐教,无比感谢中。
今天一大早开始研究Webservice,有一本不太专业的参考书,随便找了一个服务端的Wsdl,想调用其中的方法,结果搞了一天,无果,老报错,郁闷。
代码如下:
$client = new SoapClient('http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx?WSDL',array('encoding'=>'gb2312'));
$param=array('theStockCode'=>'sh600031');
$result = $client->__soapcall('getStockInfoByCode',$param);
$jg=$result->getStockInfoByCodeResult;
print_r($jg); 
?>
就这么些,不多,没有服务端代码,Soap模块什么的都已打开能检测到,用的是Apache+php+mysql;连JAVA都没装,一个方向就是专心搞PHP,运行后出现错误提示:Fatal error: Uncaught SoapFault exception: [soap:Server] 服务器无法处理请求。 ---> 未将对象引用设置到对象的实例。 in C:\Program Files\6000345.php:4 Stack trace: #0 C:\Program Files\6000345.php(4): SoapClient->__soapCall('getStockInfoByC...', Array) #1 {main} thrown in C:\Program Files\6000345.php on line 4


回复讨论(解决方案)

本帖最后由 xuzuning 于 2013-03-05 08:03:50 编辑

...$param = array('theStockCode'=>'sh600031');$result = $soapClient->__soapCall('getStockInfoByCode', array($param));
Copy after login
...$param=array('theStockCode'=>'sh600031');$result = $soapClient->getStockInfoByCode($param);print_r($result->getStockInfoByCodeResult);
Copy after login
stdClass Object
(
    [string] => Array
        (
            [0] => sh600031
            [1] => 三一重工
            [2] => 2013-03-04 15:03:08
            [3] => 10.77
            [4] => 11.78
            [5] => 11.70
            [6] => -1.01
            [7] => 10.60
            [8] => 11.70
            [9] => -8.57%
            [10] => 1208965.54
            [11] => 131792.9891
            [12] => 10.78
            [13] => 10.79
            [14] => 9.42%
            [15] => 10.78 / 517.00
            [16] => 10.77 / 855.00
            [17] => 10.76 / 744.00
            [18] => 10.75 / 627.40
            [19] => 10.74 / 935.00
            [20] => 10.79 / 309.50
            [21] => 10.80 / 2509.34
            [22] => 10.81 / 137.00
            [23] => 10.82 / 50.00
            [24] => 10.83 / 39.00
        )

)

首先,谢谢朋友的热情回复,我先试试。

原码如下,其中参考了朋友指点的代码写法 $client = new SoapClient('http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx?WSDL',array('encoding'=>'gb2312'));
$param = array('theStockCode'=>'sh600031');
 $result = $soapClient->getStockInfoByCode($param);
print_r($result->getStockInfoByCodeResult);
?>
照朋友教的,运行后,有如下错误提示。
Fatal error: Call to a member function getStockInfoByCode() on a non-object on line 4

soapClient

你的命名是$client

soapclient与$client,一个是实例化对象, 一个是变量名称,这点我还分得清楚,在程序里也没有混淆。我现在的疑惑是,自己的代码有语法错误,还是引用对象不规范。又或者是wsdl文件路径问题,我头都大了,没有头绪,好难,其实目标简单,就是将股票价格显示在客户端,有谁最好亲自试下,然后给出结果。再次感谢。

soapclient与$client,一个是实例化对象, 一个是变量名称,这点我还分得清楚,在程序里也没有混淆。我现在的疑惑是,自己的代码有语法错误,还是引用对象不规范。又或者是wsdl文件路径问题,我头都大了,没有头绪,好难,其实目标简单,就是将股票价格显示在客户端,有谁最好亲自试下,然后给出结果。再次感谢。

哦?是么。你区分清楚了?
这是什么?:
$client = new SoapClient('http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx?WSDL',array('encoding'=>'gb2312'));
$param = array('theStockCode'=>'sh600031');
 $result =  $soapClient->getStockInfoByCode($param);
print_r($result->getStockInfoByCodeResult);

明显应该是: $result =  $client->getStockInfoByCode($param);

试过了,还是不行,Fatal error: Uncaught SoapFault exception: [HTTP] Unable to parse URL in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\CreateSoap\600033.php:15 Stack trace: #0 [internal function]: SoapClient->__doRequest('__soapCall('getStockInfoByC...', Array) #2 {main} thrown 这么长的错误提示不知如何是好了。,

结贴。找到原因。php真他娘的弱,在远程服务器端调用天气预报接口成功,同样的写法调用股票接口却错误频出,新手无耐,只能啃书,书海茫茫,毫无头绪,不是不下功夫,只是搜索范围太广,不知如何是好,还好,运气来了,原来WEB调用真的很简单,想要的东西出来了,原来只有三四行脚本,但苦了我很多日子。找到WSDL,然后用语句$client = new SoapClient 加载它,这是关键的一步,接下来就是引用其中的方法了,我走了很多弯路,导致我以为自己走的路全错了。如:$param = array('theCityName'=>"南阳");
$result = $client->__soapCall('getWeatherbyCityName',array('paramters'=>$param));
成功,但换成股票接口WSDL,引用其中方法,正确传参后,失败,反复试验,终于找到解决方法,原来是数组问题,不应用以上写法,换一种写法传参就很顺利拿到东西了

如:$param = array('theCityName'=>"南阳");
$result = $client->__soapCall('getWeatherbyCityName',array('paramters'=>$param));
成功,但换成股票接口WSDL,引用其中方法,正确传参后,失败,反复试验,终于找到解决方法,原来是数组问题,不应用以上写法,换一种写法传参就很顺利拿到东西了
请楼具体说下"换成怎样的方法传参才能成功,谢谢!!!"
最近也在研究soap,希望楼主指点一二,谢谢!!!

结贴。找到原因。php真他娘的弱,在远程服务器端调用天气预报接口成功,同样的写法调用股票接口却错误频出,新手无耐,只能啃书,书海茫茫,毫无头绪,不是不下功夫,只是搜索范围太广,不知如何是好,还好,运气来了,原来WEB调用真的很简单,想要的东西出来了,原来只有三四行脚本,但苦了我很多日子。找到WSDL,然后用语句$client = new SoapClient 加载它,这是关键的一步,接下来就是引用其中的方法了,我走了很多弯路,导致我以为自己走的路全错了。如:$param = array('theCityName'=>"南阳");
$result = $client->__soapCall('getWeatherbyCityName',array('paramters'=>$param));
成功,但换成股票接口WSDL,引用其中方法,正确传参后,失败,反复试验,终于找到解决方法,原来是数组问题,不应用以上写法,换一种写法传参就很顺利拿到东西了


找到WSDL,然后用语句$client = new SoapClient 加载它,这是关键的一步,接下来就是引用其中的方法了,
为什么我引用不了其中的方法啊 ,求楼主赐教啊


Statement of this Website
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

See all articles