2017-04-12 52 views
2

不幸的是我之前从未使用过SOAP,因此我希望我能够很好地表达自己。PHP中的SOAP调用根本不起作用

我有以下的SOAP请求(它是在HPSM创建门票):

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://schemas.hp.com/SM/7" xmlns:com="http://schemas.hp.com/SM/7/Common" xmlns:xm="http://www.w3.org/2005/05/xmlmime"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <ns:SubmitIntApiIncidentRequest attachmentInfo="?" attachmentData="?" ignoreEmptyElements="true" updateconstraint="-1"> 
     <ns:model query="?"> 
      <ns:keys query="?" updatecounter="?"> 
       <!--Optional:--> 
       <ns:id type="Decimal" mandatory="?" readonly="?">?</ns:id> 
      </ns:keys> 
      <ns:instance query="?" uniquequery="?" recordid="?" updatecounter="?"> 
       <!--Optional:--> 
       <ns:registrationId type="String" mandatory="?" readonly="0">HPSM Registration ID</ns:registrationId> 
       <!--Optional:--> 
       <ns:contactId type="String" mandatory="?" readonly="?">???</ns:contactId> 
       <!--Optional:--> 
       <ns:affectedUserId type="String" mandatory="?" readonly="?">User ID</ns:affectedUserId> 
       <!--Optional:--> 
       <ns:serviceId type="String" mandatory="?" readonly="?">?</ns:serviceId> 
       <!--Optional:--> 
       <ns:affectedCiId type="String" mandatory="?" readonly="?">?</ns:affectedCiId> 
       <!--Optional:--> 
       <ns:priority type="String" mandatory="?" readonly="?">?</ns:priority> 
       <!--Optional:--> 
       <ns:title type="String" mandatory="?" readonly="?">?</ns:title> 
       <!--Optional:--> 
       <ns:description type="String" mandatory="?" readonly="?">description</ns:description> 
       <!--Optional:--> 
       <ns:returnCode type="String" mandatory="?" readonly="?">?</ns:returnCode> 
       <!--Optional:--> 
       <ns:returnMessage type="String" mandatory="?" readonly="?">?</ns:returnMessage> 
       <!--Optional:--> 
       <ns:returnTicketId type="String" mandatory="?" readonly="?">?</ns:returnTicketId> 
       <!--Optional:--> 
       <ns:submittedBy type="String" mandatory="?" readonly="?">?</ns:submittedBy> 
       <!--Optional:--> 
       <ns:submitterGroup type="String" mandatory="?" readonly="?">?</ns:submitterGroup> 
       <!--Optional:--> 
       <ns:assignmentGroup type="String" mandatory="?" readonly="?">?</ns:assignmentGroup> 
       <!--Optional:--> 
       <ns:externalReferenceId type="String" mandatory="?" readonly="?">?</ns:externalReferenceId> 
       <!--Optional:--> 
       <ns:category type="String" mandatory="?" readonly="?">?</ns:category> 
       <!--Optional:--> 
       <ns:resolveImmediately type="Boolean" mandatory="?" readonly="?">?</ns:resolveImmediately> 
       <!--Optional:--> 
       <ns:solutionCode type="String" mandatory="?" readonly="?">?</ns:solutionCode> 
       <!--Optional:--> 
       <ns:solution type="String" mandatory="?" readonly="?">?</ns:solution> 
       <!--Optional:--> 
       <ns:contactInfo type="String" mandatory="?" readonly="?">?</ns:contactInfo> 
       <!--Optional:--> 
       <ns:incidentType type="String" mandatory="?" readonly="?">?</ns:incidentType> 
       <!--Optional:--> 
       <ns:attachments> 
        <!--Zero or more repetitions:--> 
        <com:attachment xm:contentType="application/?" href="?" contentId="?" action="?" name="?" type="?" len="?" charset="?" upload.by="?" upload.date="?" attachmentType="?">cid:933455187673</com:attachment> 
       </ns:attachments> 
      </ns:instance> 
      <!--Optional:--> 
      <ns:messages> 
       <!--Zero or more repetitions:--> 
       <com:message type="String" mandatory="?" readonly="?" severity="?" module="?">?</com:message> 
      </ns:messages> 
     </ns:model> 
     </ns:SubmitIntApiIncidentRequest> 
    </soapenv:Body> 
</soapenv:Envelope> 

现在我已经在我的soapcall.php文件下面的代码:

<?php   

    $wsdl ='asdf?wsdl'; 
    $client = new SoapClient($wsdl, array('login' => "user", 'password' => "pw")); 


    $request = array(
     'SubmitIntApiIncident'=>(array(
      'model' => '', 
      'registrationID' => 'registrationid', 
      'contactId' => 'me', 
      'affectedUserId' => 'affuser', 
      'serviceId' => 'serviceid', 
      'affectedCiId' => '', 
      'priority' => '4', 
      'title' => 'Test Title', 
      'description' => 'description', 
      'submittedBy' => 'me', 
      'assignmentGroup' => 'assignment group', 
      'externalReferenceId' => '', 
      'category' => 'incident', 
      'resolveImmediately' => '' 
     ))); 

    $response = $client->__soapCall("SubmitIntApiIncident", $request); 
    var_dump($response); 


?> 

这不一切工作 - 现在我没有得到任何错误信息,只是一个空白页。但是每次我在代码中改变一些东西时都会有另一个错误信息。所以我甚至不知道我是否在正确的轨道上,或者我所尝试的一切只会让事情变得更糟。

我真的很感激,如果你能告诉我,如果我的代码中有任何大的错误,或者我可以如何成功地提交一个包含php文件的票据。

+0

也许你可以在这里找到一些信息:http://stackoverflow.com/questions/3572414/how -do -i-see-the-actual-xml-generated-by-php-soap-client-class – junkfoodjunkie

+0

谢谢,但不幸的是我找不到任何解决方案。 –

+0

在PHP代码的头部添加'error_reporting(E_ALL | E_NOTICE);'查看所有错误和警告。 – Adder

回答

1

使用__soapCall方法是最好的方法之一。您也可以直接使用操作名称作为方法,如$client->SubmitIntApiIncident()

为了避免浪费时间寻找问题,您应该明确使用WSDL生成器来生成php生成器。

使用WSDL到PHP发电机的优点是很多的:

  • 构建请求,而不知道如何构建它,只需使用一个很好的IDE有自动完成展示你传递什么数据
  • 发送使用处理干净错误和响应
  • 得到干净的物体响应生成的类的方法要求从生成CLASSE
  • 得到帮助的目标错误
  • 停止想,如果请求的格式格式化
  • ...

尝试PackageGenerator项目