Heim >Backend-Entwicklung >PHP-Tutorial >PHP调用C#Webservice传数组参数的问题

PHP调用C#Webservice传数组参数的问题

WBOY
WBOYOriginal
2016-06-23 13:55:231004Durchsuche

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"



  
    
      
        
          string
          string
        

        
          string
          string
        

      

      string
      string
    

  

---------------------------------------------------------------------------------------
返回:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length



  
    
      
        schemaxml

    

  

-----------------------------------------------------------------------------------

<?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楼的回复给删除,我一会结贴。
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:请教一个PHPExcel问题Nächster Artikel:类继承的问题