4

I'm trying to create a SOAP server in my ZF2 application that I can import with Visual Studio using the wizard into a C# application. I've already created the service and tested it using soapUI. I ran the WS-I compliance test in soapUI and my service passed it. However, when I try to add the service into a C# application using Visual C# Express 2008, it says that the HTML document does not have webservice discovery information.

Here is the code I'm using in my ZF2 controller:

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();
  }
}

This is the SoapClass class:

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;
  }
}

Any ideas?

3 Answers 3

4

After reading and re-reading over and over again the few posts and documentation I found on this, finally came across with de solution:

The SoapClass is fine, but at the moment of generating the wsdl and the server I had to make some changes:

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();
  }
}
1
  • I did what you said, still can not import to visual studio! Any clue?
    – hpaknia
    Commented Oct 24, 2013 at 16:36
2

I think you need to specify the transport:

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

And the header should be:

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

Here you can read about several issues regarding the compatibility of ZF SOAP component:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.