Do you know the server-side Wsdl and do not write the server-side code? can you call the server-side Method by writing only the client-side code?

Source: Internet
Author: User
Do you know the server-side Wsdl and do not write the server-side code? can you call the server-side Method by writing only the client-side code? I am very grateful to you for your advice.
Early in the morning, I started to study Webservice. I had a reference book that was not very professional. I found a server-side Wsdl and wanted to call the method. The result was one day, but it was fruitless. I always reported an error and got depressed.
The code is as follows:
$ 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 );
?>
So far, there are not many, there is no server code, and the Soap module can be opened and detected. Apache + php + mysql is used. even JAVA is not installed. One direction is to focus on PHP, the following error occurs: Fatal error: Uncaught SoapFault exception: [soap: Server] The Server cannot process the request. ---> The object reference is not set to the instance of the object. 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


Reply to discussion (solution)

This post was last edited by xuzuning at 08:03:50 on

...$param = array('theStockCode'=>'sh600031');$result = $soapClient->__soapCall('getStockInfoByCode', array($param));
Or
...$param=array('theStockCode'=>'sh600031');$result = $soapClient->getStockInfoByCode($param);print_r($result->getStockInfoByCodeResult);
StdClass Object
(
[String] => Array
(
[0] => sh600031
[1] => Sany
[2] => 15:03:08
[3] = & gt; 10.77
[4] = & gt; 11.78
[5] = & gt; 11.70
[6] =>-1.01.
[7] = & gt; 10.60
[8] = & gt; 11.70
[9] =>-8.57%.
[10] => 1208965.54.
[11] => 131792.9891.
[12] = & gt; 10.78
[13] = & gt; 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
)

)

First, thank you for your enthusiastic reply. let me try it first.

The source code is as follows. I have referenced the code written by a friend. $ 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 );
?>
The following error message is displayed after running as instructed by a friend.
Fatal error: Call to a member function getStockInfoByCode () on a non-object on line 4

SoapClient

Your name is $ client

Soapclient and $ client are instantiated objects and variable names, which are clearly known and not confused in the program. I am wondering whether my code has syntax errors or the reference object is not standard. Or the wsdl file path problem. I have a big head and no clue. it is difficult. In fact, the goal is simple, that is, to display the stock price on the client. who 'd better try it, then give the result. Thanks again.

Soapclient and $ client are instantiated objects and variable names, which are clearly known and not confused in the program. I am wondering whether my code has syntax errors or the reference object is not standard. Or the wsdl file path problem. I have a big head and no clue. it is difficult. In fact, the goal is simple, that is, to display the stock price on the client. who 'd better try it, then give the result. Thanks again.

Oh? Yes. Are you clear?
What is this? :
$ 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 );

It should be: $ result = $ client-> getStockInfoByCode ($ param );

I tried it, but I still cannot. 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 errors so long that I don't know how to handle them .,

Close the post. Find the cause. Php is really weak, and the weather forecast interface is successfully called on the remote server. The same method of calling the stock interface is often incorrect, and the novice is impatient. he can only chew books and have no clue, it's just that the search range is too wide. I don't know how to do it. Fortunately, luck is coming. it turns out that WEB calls are really simple, and what I want is coming out. it turns out there are only three or four lines of scripts, but I have suffered many days. Find the WSDL and use the statement $ client = new SoapClient to load it. this is a key step. Next, we will reference the method. I have taken many detours, as a result, I thought I had taken the wrong path. For example: $ param = array ('thecityname' => "Nanyang ");
$ Result = $ client->__ soapCall ('getweatherbycityname', array ('paramters '=> $ param ));
Succeeded, but changed to the stock interface WSDL and referenced the method. after passing the parameter correctly, failed and tried again and again, finally found the solution. it turned out to be an array problem and did not apply the above method, in another way, passing parameters will make it easy to get things.

For example: $ param = array ('thecityname' => "Nanyang ");
$ Result = $ client->__ soapCall ('getweatherbycityname', array ('paramters '=> $ param ));
Succeeded, but changed to the stock interface WSDL and referenced the method. after passing the parameter correctly, failed and tried again and again, finally found the solution. it turned out to be an array problem and did not apply the above method, in another way, passing parameters will make it easy to get things.
Please refer to the following link for details: "How can I transfer parameters successfully? thank you !!! "
I am also studying soap recently. I hope you can give me some advice. thank you !!!

Close the post. Find the cause. Php is really weak, and the weather forecast interface is successfully called on the remote server. The same method of calling the stock interface is often incorrect, and the novice is impatient. he can only chew books and have no clue, it's just that the search range is too wide. I don't know how to do it. Fortunately, luck is coming. it turns out that WEB calls are really simple, and what I want is coming out. it turns out there are only three or four lines of scripts, but I have suffered many days. Find the WSDL and use the statement $ client = new SoapClient to load it. this is a key step. Next, we will reference the method. I have taken many detours, as a result, I thought I had taken the wrong path. For example: $ param = array ('thecityname' => "Nanyang ");
$ Result = $ client->__ soapCall ('getweatherbycityname', array ('paramters '=> $ param ));
Succeeded, but changed to the stock interface WSDL and referenced the method. after passing the parameter correctly, failed and tried again and again, finally found the solution. it turned out to be an array problem and did not apply the above method, in another way, passing parameters will make it easy to get things.


Find the WSDL and load it with the statement $ client = new SoapClient. this is a key step. Next, we will reference the method,
Why can't I reference these methods? could you please enlighten me?


You

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.