【问题标题】:Jax Ws with PHP client that always send Null parm带有始终发送 Null 参数的 PHP 客户端的 Jax Ws
【发布时间】:2013-02-04 13:38:14
【问题描述】:

我创建了一个 JaxWs 服务。用户试图用 PHP 客户端调用它,唯一的参数是一个字符串。当我使用 Eclipse Web 服务浏览器(测试器)时,它很好。当用户尝试使用 PHP 时,我在方法中收到一个空参数。我还没有对 wsdl 或代码进行任何定制。在此先感谢您的任何指点...

方法

    @WebService(endpointInterface = "my.endpoint.class")
    public class ExternalReportsImpl implements ExternalReports {
private org.w3c.dom.Document doc;
@Resource
private WebServiceContext context;
private enum Types {
    tfbData, tfbRate, tfbSupport, tfbMakes, tfbVin, tfbSave, tfbRetrieve;
}
@Override

public String getReports(String xmlSource){
    XmlHelper xh;
    SupportTables support =  new SupportTables();
    Connection con = null;  
    Policy policy  = null;
    String schema  = "";
    String ret     = "";
    ServletContext servletContext = (ServletContext)   context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
    try {
        xh = new XmlHelper();
        doc = xh.loadDoc(xmlSource);
             }

WSDL 片段

<message name="getReports"><part name="parameters" element="tns:getReports"/></message><message name="getReportsResponse"><part name="parameters" element="tns:getReportsResponse"/></message><portType name="ExternalReports"><operation name="getReports"><input wsam:Action="http://my.class/ExternalReports/getReportsRequest" message="tns:getReports"/><output wsam:Action="http://my.class/ExternalReports/getReportsResponse" message="tns:getReportsResponse"/></operation></portType>

PHP 客户端

   error_reporting(E_ALL);


    $url = 'http://my.endpoint/ExternalReportsWebService?wsdl';

    $client = new SoapClient($url);

    class getReports {
  function __construct($arg0) {
    $this->getReports = $arg0;
}
    }

   class getReportsResponse {
function __construct($arg0='') {
    $this->getReportsResponse = $arg0;
}
     }

     //$GR = new getReports(file_get_contents("test/test.xml") );
     $GR = new getReports("test") );
     $GRR = new getReportsResponse();

      $report = new SoapVar( $GR  , SOAP_ENC_OBJECT, 'getReports', $url);
      $response = new SoapVar( $GRR  , SOAP_ENC_OBJECT, 'getReportsResponse', $url);

      echo nl2br(htmlspecialchars(print_r($client->getReports($report, $response), true)));

将此代码添加到 PHP CLIENT

     echo "<br> LAST REQUEST <br>"  ;
     echo $client->__getLastRequest();
     echo " <br> Functions <br>"  ;
     echo $client->__getFunctions();
     echo " <br> Types <br>"  ;
     echo $client->__getTypes();
     echo "<br> Request headers <br>"  ;
     echo $client->__getLastRequestHeaders();

客户追踪结果

    LAST REQUEST
        TEST
    Functions
       Array
    Types
       Array
    Request headers
       POST /myApp/ExternalReportsWebService HTTP/1.1 Host: localhost:8080          Connection: Keep-Alive User-Agent: PHP-SOAP/5.3.14 Content-Type: text/xml; charset=utf-8 SOAPAction: "" Content-Length: 531 

【问题讨论】:

  • 嗯,很难说……您是否尝试过跟踪从 PHP 客户端发送的 SOAP 消息?
  • 我已经在我的 Java 端进行了调试。两天前我开始编写 PHP 来尝试解决这个问题。我尝试了所有可以为 PHP 客户端找到的示例,但没有任何效果。我将研究 PHP 中的 Soap 跟踪
  • @home 当我设置跟踪时,我看到了应该使用 echo $client->__getLastRequest(); 发送的字符串 parm;

标签: java php web-services soap jax-ws


【解决方案1】:

找到这个链接

http://www.lampjunkie.com/2010/03/get-phps-soapclient-to-speak-with-javas-jax-ws/

我的架构已命名为 params

 <xs:schema version="1.0" targetNamespace="http://my.namespace/"><xs:element name="getReports" type="tns:getReports"/><xs:element name="getReportsResponse" type="tns:getReportsResponse"/><xs:complexType name="getReports"><xs:sequence><xs:element name="arg0" type="xs:string" minOccurs="0"/></xs:sequence></xs:complexType><xs:complexType name="getReportsResponse"><xs:sequence><xs:element name="return" type="xs:string" minOccurs="0"/></xs:sequence></xs:complexType></xs:schema> 

必须添加

$addRequest = new stdClass();
$addRequest->argO = "String I was sending";
$response = $client->add($addRequest);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    • 1970-01-01
    相关资源
    最近更新 更多