PHP调用C#Webservice传数组参数的问题
POST /xxxxxxxxxxxx/ws/commonservice.asmx HTTP/1.1
Host: 202.82.66.147
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://xxxxxxxxxxxxxx/webservices/queryVoyageRoute_onWeb"
---------------------------------------------------------------------------------------
返回:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
-----------------------------------------------------------------------------------
<?php$client = new SoapClient('http://xxxxxxxxxxxxx/ws/commonservice.asmx?WSDL');//这个SOAP地址要换成你自己的$client->soap_defencoding = 'utf-8'; $client->decode_utf8 = false; $client->xml_encoding = 'utf-8'; $setoffdate=array(0=>"setoffdate",1=>"2014-02-10"); $fromportcode=array(0=>"fromportcode",1=>"SK");$toportcode=array(0=>"toportcode",1=>"ZH");$parameters=array(0=>$setoffdate,1=>$fromportcode,2=>$toportcode);$param = array(0=>$parameters,1=>"SKG",2=>"E");//$param["param1"]="01";//$param["param2"]="02";//$result = $client->__soapCall("GetArticle", array( $param ));$result = $client->__Call("queryVoyageRoute_onWeb", array( $param ));if (is_soap_fault($result)){ trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);}else{ $data = $result->queryVoyageRoute_onWebResult ; //这里返回的是类,必须使用->得到元素的值 print_r($data); //$city_xml = simplexml_load_string($city); }?>
提示错误:
Notice: Undefined property: stdClass::$queryVoyageRoute_onWebResult in D:\xampp\htdocs\WS\index.php on line 21
如何传参数过去类型不对?要怎么传过去呢?
回复讨论(解决方案)
你先检查 queryVoyageRoute_onWebResult 是否拼写错误
没错则:
print_r($result); 看看结果
如果结果不包含期望内容
则检查传递的参数是否正确
由于没有看到你的 WSDL,所以不知道正确的参数该如何写
参数应是一个关联数组(关联键是WSDL),可能还是多维的
而你的是一个多维的下标数组
我已经搞定了,把参数名加进去就可以。
$param = array('parameters'=>$parameters,'portcompanyCode'=>"SKG",'lang'=>"C");
但是,中文调出来的出现一片乱码,怎么能知道,他是用哪种编码呢?
???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)JLFZ???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)SJCD???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)XYLC???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)SKWEB???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)AYGJ???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)SHYG???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)BZLY???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)LHMT???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)STSJD???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)QSHK???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)KBSJ???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)YGJD???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)WYN???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)HGJD???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)TGGY???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)ZNHY???娓???捣涔?床娓?SKZH娴? ??KKJ2014-02-10 07:30MSK-ZH?????(65)缍????(27)?????(0)璐靛???(12)MHZX
SOAP 嘛,当然是 utf-8 的啦
航班信息?
SOAP 嘛,当然是 utf-8 的啦
航班信息?
$client->xml_encoding = 'utf-8';
此处不是已经xml_encoding = 'utf-8'; 了吗?为何还是乱码?
SOAP 嘛,当然是 utf-8 的啦
航班信息?
搞定了,请版本帮我把3楼的回复给删除,谢谢。
header("content-type:text/html;charset=utf-8");
没错,是 utf-8 的
你当 gbk 显示当然就乱码了
没错,是 utf-8 的
你当 gbk 显示当然就乱码了
版主,麻烦你再看看,为何,我想print_r个别的列的表值不行呢?全部是SimpleXMLElement Object ( )
上面的多了一个.
print_r($child->toport).;
用 simplexml_load_string 加载得到的都是 SimpleXMLElement 对象
具体要如何分析要是具体的数据而定
你可以贴出 $result 并说明需求
页面结果:
蛇口港?仔客运码头SKMAC金星JX2014-02-10 09:30MSK-MAC普通位(28)头等位(5)特等位(8)SKG蛇口港?仔客运码头SKMAC金星JX2014-02-10 09:30MSK-MAC普通位(28)头等位(5)特等位(8)XYLC蛇口港?仔客运码头SKMAC金星JX2014-02-10 09:30MSK-MAC普通位(28)头等位(5)特等位(8)SHYG蛇口港?仔客运码头SKMAC金星JX2014-02-10 09:30MSK-MAC普通位(28)头等位(5)特等位(8)SJCD蛇口港?仔客运码头SKMAC金星JX2014-02-10 09:30MSK-MAC普通位(28)头等位(5)特等位(8)BAKY蛇口港?仔客运码头SKMAC金星JX2014-02-10 09:30MSK-MAC普通位(28)头等位(5)特等位(8)ZYJD蛇口港?仔客运码头SKMAC金星JX2014-02-10 09:30MSK-MAC普通位(28)头等位(5)特等位(8)YJGY
结果源文件:
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"><NewDataSet xmlns=""><Table diffgr:id="Table1" msdata:rowOrder="0"><FROMPORT>蛇口港</FROMPORT><TOPORT>?仔客运码头</TOPORT><FPORTCODE>SK</FPORTCODE><TPORTCODE>MAC</TPORTCODE><SHIP>金星</SHIP><SHIPCODE>JX</SHIPCODE><SETOFFTIME>2014-02-10 09:30</SETOFFTIME><SELLSTATUS>M</SELLSTATUS><LINECODE>SK-MAC</LINECODE><TICKETNUM>普通位(28)头等位(5)特等位(8)</TICKETNUM><CLIENTCODE>SKG</CLIENTCODE></Table><Table diffgr:id="Table2" msdata:rowOrder="1"><FROMPORT>蛇口港</FROMPORT><TOPORT>?仔客运码头</TOPORT><FPORTCODE>SK</FPORTCODE><TPORTCODE>MAC</TPORTCODE><SHIP>金星</SHIP><SHIPCODE>JX</SHIPCODE><SETOFFTIME>2014-02-10 09:30</SETOFFTIME><SELLSTATUS>M</SELLSTATUS><LINECODE>SK-MAC</LINECODE><TICKETNUM>普通位(28)头等位(5)特等位(8)</TICKETNUM><CLIENTCODE>XYLC</CLIENTCODE></Table><Table diffgr:id="Table3" msdata:rowOrder="2"><FROMPORT>蛇口港</FROMPORT><TOPORT>?仔客运码头</TOPORT><FPORTCODE>SK</FPORTCODE><TPORTCODE>MAC</TPORTCODE><SHIP>金星</SHIP><SHIPCODE>JX</SHIPCODE><SETOFFTIME>2014-02-10 11:00</SETOFFTIME><SELLSTATUS>M</SELLSTATUS><LINECODE>SK-MAC</LINECODE><TICKETNUM>普通位(42)头等位(31)特等位(0)</TICKETNUM><CLIENTCODE>YJGY</CLIENTCODE></Table><Table diffgr:id="Table43" msdata:rowOrder="42"><FROMPORT>蛇口港</FROMPORT><TOPORT>?仔客运码头</TOPORT><FPORTCODE>SK</FPORTCODE><TPORTCODE>MAC</TPORTCODE><SHIP>迅隆5</SHIP><SHIPCODE>XL5</SHIPCODE><SETOFFTIME>2014-02-10 11:00</SETOFFTIME><SELLSTATUS>M</SELLSTATUS><LINECODE>SK-MAC</LINECODE><TICKETNUM>普通位(42)头等位(31)特等位(0)</TICKETNUM><CLIENTCODE>SKXRD</CLIENTCODE></Table><Table diffgr:id="Table44" msdata:rowOrder="43"><FROMPORT>蛇口港</FROMPORT><TOPORT>?仔客运码头</TOPORT><FPORTCODE>SK</FPORTCODE><TPORTCODE>MAC</TPORTCODE><SHIP>迅隆5</SHIP><SHIPCODE>XL5</SHIPCODE><SETOFFTIME>2014-02-10 19:00</SETOFFTIME><SELLSTATUS>M</SELLSTATUS><LINECODE>SK-MAC</LINECODE><TICKETNUM>普通位(148)头等位(7)特等位(8)</TICKETNUM><CLIENTCODE>SCP</CLIENTCODE></Table></NewDataSet></diffgr:diffgram>
用 simplexml_load_string 加载得到的都是 SimpleXMLElement 对象
具体要如何分析要是具体的数据而定
你可以贴出 $result 并说明需求
我只想print_r:FROMPORT、TOPORT、SETOFFTIME的字段信息
$key = array('FROMPORT', 'TOPORT', 'SETOFFTIME');foreach($obj_xml->NewDataSet->Table as $item) { foreach($key as $k) { $t[$k] = strval($item->$k); } $res[] = $t;}print_r($res);
Array( [0] => Array ( [FROMPORT] => 蛇口港 [TOPORT] => ?仔客运码头 [SETOFFTIME] => 2014-02-10 09:30 ) [1] => Array ( [FROMPORT] => 蛇口港 [TOPORT] => ?仔客运码头 [SETOFFTIME] => 2014-02-10 09:30 ) [2] => Array ( [FROMPORT] => 蛇口港 [TOPORT] => ?仔客运码头 [SETOFFTIME] => 2014-02-10 11:00 ) [3] => Array ( [FROMPORT] => 蛇口港 [TOPORT] => ?仔客运码头 [SETOFFTIME] => 2014-02-10 11:00 ) [4] => Array ( [FROMPORT] => 蛇口港 [TOPORT] => ?仔客运码头 [SETOFFTIME] => 2014-02-10 19:00 ))
$key = array('FROMPORT', 'TOPORT', 'SETOFFTIME');foreach($obj_xml->NewDataSet->Table as $item) { foreach($key as $k) { $t[$k] = strval($item->$k); } $res[] = $t;}print_r($res);
Array( [0] => Array ( [FROMPORT] => 蛇口港 [TOPORT] => ?仔客运码头 [SETOFFTIME] => 2014-02-10 09:30 ) [1] => Array ( [FROMPORT] => 蛇口港 [TOPORT] => ?仔客运码头 [SETOFFTIME] => 2014-02-10 09:30 ) [2] => Array ( [FROMPORT] => 蛇口港 [TOPORT] => ?仔客运码头 [SETOFFTIME] => 2014-02-10 11:00 ) [3] => Array ( [FROMPORT] => 蛇口港 [TOPORT] => ?仔客运码头 [SETOFFTIME] => 2014-02-10 11:00 ) [4] => Array ( [FROMPORT] => 蛇口港 [TOPORT] => ?仔客运码头 [SETOFFTIME] => 2014-02-10 19:00 ))
谢谢版主,麻烦版主把8楼的回复给删除,我一会结贴。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
