PHP SOAP属性.net Web服务

时间:2011-01-06 05:03:05

标签: php .net soap types

我花了一周的时间寻找一个我能理解的答案。我是网络发展中国家的新手。

我的问题在于生成一条肥皂消息,需要设置属性中的值以及元素本身。

以下是我尝试创建的SOAP消息的简化示例。

客户= PHP
Server = .NET

需要SOAP消息:

 <PingRequest EchoToken="string">
      <EchoData>string</EchoData>
 </PingRequest>

WSDL部分

  <s:element name="PingRequest" type="s0:PingRequest" />
  <s:complexType name="PingRequest">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="EchoData" type="s:string" />
    </s:sequence>
    <s:attribute name="EchoToken" type="s:string" />
  </s:complexType>

我花了很多时间试图了解如何将类和其他对象传递给Web服务,但是,我的大脑让我失望了。如果我的问题有点模糊,请道歉。这是我尝试调用我的webservice:

    <?php
    //connection to wsdl
    $client = new SoapClient('http://localhost/ws.asmx?wsdl',
                array(  "trace"          => 1,
                        "exceptions"     => 0
                ));

    try {
        // Ping = Function
        // PingRequest = method?
        $result = $client->PingRequest(array('EchoData' => 'moo'));

    } catch (SOAPFAULT $f){
    }

    echo "\n The Result: \n";
    print_r($result);

    print "<pre>";
    print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
    print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
    print "</pre>";
    ;

?>

请求:

<ns1:PingRequest>
   <ns1:EchoData>moo</ns1:EchoData>
</ns1:PingRequest>

任何帮助都是竖起大拇指。

修改 感谢丽莎:我能够为此创建一个类:但我还是不明白

class PingRequest {
  public $EchoData; // string
  public $EchoToken; // string
  public $TimeStamp; // dateTime
  public $Target; // PingTarget
  public $Version; // decimal
  public $TransactionIdentifier; // string
  public $SequenceNmbr; // nonNegativeInteger
  public $TransactionStatusCode; // PingRequestStatusCode
  public $RetransmissionIndicator; // boolean
}

让它变得非常简单。谢谢

创建一个名为webservice类的新类变量,然后为您希望传递的每个元素或属性创建stdclasses。 (必须使用提供的lisa类生成器。

1 个答案:

答案 0 :(得分:2)

您需要从wsdl文件生成php类。 http://www.urdalen.no/wsdl2php/index.php

相关问题