【问题标题】:Zend Framework 2 SOAP not compatible with .NETZend Framework 2 SOAP 与 .NET 不兼容
【发布时间】:2012-11-27 00:34:11
【问题描述】:

我正在尝试在我的 ZF2 应用程序中创建一个 SOAP 服务器,我可以使用向导通过 Visual Studio 将它导入到 C# 应用程序中。我已经创建了服务并使用soapUI 对其进行了测试。我在soapUI 中运行了WS-I 合规性测试,我的服务通过了它。但是,当我尝试使用 Visual C# Express 2008 将服务添加到 C# 应用程序中时,它说 HTML 文档没有 Web 服务发现信息。

这是我在 ZF2 控制器中使用的代码:

public function exampleAction() {
  if (isset($_GET['wsdl'])) {
    $soapAutoDiscover = new AutoDiscover();
    $soapAutoDiscover->setBindingStyle(array('style' => 'document'));
    $soapAutoDiscover->setOperationBodyStyle(array('use' => 'literal'));
    $soapAutoDiscover->setClass('SoapClass');
    $soapAutoDiscover->setUri($serverUrl);
    echo $soapAutoDiscover->generate()->toXml();
  } else {
    $soap = new Server($serverUrl . '?wsdl');
    $soap->setClass('SoapClass');
    $soap->handle();
  }
}

这是 SoapClass 类:

class SoapClass{

  /**
   * returns the sum of two parameters
   * @param int $a
   * @param int $b
   * @return int
   */
  public function sum ($a, $b){
    return $a + $b;
  }

  /**
   * twice function doc
   * @param int $a
   * @return int
   */
  public function twice($a){
    return $a * 2;
  }
}

有什么想法吗?

【问题讨论】:

    标签: c# php .net soap zend-framework2


    【解决方案1】:

    在一遍又一遍地阅读我在这方面找到的几篇文章和文档之后,终于找到了解决方案:

    SoapClass 很好,但是在生成 wsdl 和服务器时,我必须进行一些更改:

    public function exampleAction() {
      if (isset($_GET['wsdl'])) {
        //this is new:
        $soapAutoDiscover = new AutoDiscover(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence());
        $soapAutoDiscover->setBindingStyle(array('style' => 'document'));
        $soapAutoDiscover->setOperationBodyStyle(array('use' => 'literal'));
        $soapAutoDiscover->setClass('SoapClass');
        $soapAutoDiscover->setUri($serverUrl);
        //so this is:
        header("Content-Type: text/xml");
        echo $soapAutoDiscover->generate()->toXml();
      } else {
        $soap = new Server($serverUrl . '?wsdl');
        //drop this:
        //$soap->setClass('SoapClass');
        //and instead, add this:
        $soap->setObject(new DocumentLiteralWrapper(new SoapClass()));
        $soap->handle();
      }
    }
    

    【讨论】:

    • 按照你说的做了,还是无法导入visual studio!有什么线索吗?
    【解决方案2】:

    我认为您需要指定传输:

    $style = array('style'=>'document', 'transport'=>'http://schemas.xmlsoap.org/soap/http');
    $soapAutoDiscover->setBindingStyle($style);
    

    标题应该是:

    header('Content-type: application/soap+xml');
    

    【讨论】:

      【解决方案3】:

      您可以在此处阅读有关 ZF SOAP 组件兼容性的几个问题:

      http://framework.zend.com/issues/browse/ZF-6349

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-13
        • 2023-03-10
        • 1970-01-01
        相关资源
        最近更新 更多