dongyoudi1342 2016-08-10 15:23
浏览 59
已采纳

如何使用php进行简单的SOAP调用?

I am making call to Zefix Webservice Schnittstelle using Php. I don't know how to consume SOAP. Following details are given

<message name="SearchByNameRequestMsg">
    <part name="body" element="zefix:searchByNameRequest"/>
</message>

<operation name="SearchByName">
    <input message="zefix:SearchByNameRequestMsg"/>
    <output message="zefix:ShortResponseMsg"/>
</operation>

<operation name="SearchByName">
    <soap:operation soapAction="http://soap.zefix.admin.ch/SearchByName"/>
    <input>
    <soap:body use="literal"/>
    </input>
    <output>
        <soap:body use="literal"/>
    </output>
</operation>

I have tried following php code and some other

$url = "http://test-e-service.fenceit.ch:80/ws-zefix-1.7/ZefixService";



$soap_request  = "<?xml version=\"1.0\"?>
";
  $soap_request .= "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">
";
  $soap_request .= "   <soap:Body>
";
  $soap_request .= "    <SearchByName xmlns=\"http://soap.zefix.admin.ch/SearchByName\">
";
  $soap_request .= "      <Name>Autocenter</Name>
";
  $soap_request .= "    </SearchByName>
";
  $soap_request .= "  </soap:Body>
";
  $soap_request .= "</soap:Envelope>";

  $header = array(
    "Content-type: text/xml;charset=\"utf-8\"",
    "Accept: text/xml",
    "Cache-Control: no-cache",
    "Pragma: no-cache",
    "SOAPAction: \"run\"",
    "Content-length: ".strlen($soap_request),
  );


$soap_do = curl_init(); 
curl_setopt($soap_do, CURLOPT_URL,            $url );   
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10); 
curl_setopt($soap_do, CURLOPT_TIMEOUT,        10); 
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($soap_do, CURLOPT_POST,           true ); 
curl_setopt($soap_do, CURLOPT_POSTFIELDS,    $soap_request); 
curl_setopt($soap_do, CURLOPT_HTTPHEADER,     array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($soap_request) )); 
curl_setopt($soap_do, CURLOPT_USERPWD, $user . ":" . $password);

$result = curl_exec($soap_do);
 if($result === false) {
    $err = 'Curl error: ' . curl_error($soap_do);
    curl_close($soap_do);
    print $err;
 } else {
    curl_close($soap_do);
    print 'Operation completed without any errors';
 }


print_r($result);

XML provided

  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 模型导入SP后贴图纹理只有一个,拆了四张UV的,怎么解决?
      • ¥15 检索带order by 非常慢
      • ¥20 python 爬虫 token 加密方式
      • ¥20 IAR环境报错reading CPU status failed
      • ¥15 数组问题,刚学C语言
      • ¥20 Python如何读取指定播放设备的音频帧?
      • ¥15 用dnspy修改游戏数据报错
      • ¥15 关于unity打包成webgl后页面上不显示服务端接收到的数据的问题
      • ¥16 (大一)有偿 想学会 excel数据处理和分析🥹
      • ¥15 matlab导入工具箱提示:此类型的变量不支持使用点进行索引错误