Giter VIP home page Giter VIP logo

Comments (18)

piotrooo avatar piotrooo commented on May 30, 2024

Can you show body of method getAuthors() and Author class?

from wsdl-creator.

rhelms avatar rhelms commented on May 30, 2024

Hi

The getAuthors class is

/**
 * getAuthors
 *
 * @desc Get all authors
 * @return wrapper[] $authors @className=\App\Soap\Author
 */
public function getAuthors() {
    $request = new Request('authors/index');
    $response = new Response();
    $controller = new AuthorsController($request, $response);
    $controller->setAction('index');
    $controller->invokeAction();
    $authors = array();
    foreach ($controller->viewVars['authors'] as $author) {
        $obj = new Author();
        $obj->id = $author->id;
        $obj->name = $author->name;
        $obj->created = $author->created;
        $obj->modified = $author->modified;
        $authors[] = $obj;
    }
    return $authors;
}

The request in SoapUI is

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://intalio.reubenh3.dev.otw.internal/app/controller/intaliowebservicesoapserver">
<soapenv:Header/>
<soapenv:Body>
  <int1:getAuthors xmlns:int1="http://intalio-webservice.reubenh3.dev.otw.internal/app/soap/intaliowebservicesoapserver"/>
</soapenv:Body>
</soapenv:Envelope>

from wsdl-creator.

piotrooo avatar piotrooo commented on May 30, 2024

I was try to implement your example:

$wsdl = new WSDLCreator('TestSoapServer', 'http://localhost/wsdl-creator/examples/TestSoapServer.php');
$wsdl->setNamespace("http://foo.bar/");

if (isset($_GET['wsdl'])) {
    $wsdl->renderWSDL();
    exit;
}

$wsdl->renderWSDLService();

$server = new SoapServer(null, array(
    'uri' => 'http://localhost/wsdl-creator/examples/TestSoapServer.php'
));
$server->setClass('TestSoapServer');
$server->handle();

class Test
{
    /**
     * @type string
     */
    public $name;
    /**
     * @type int
     */
    public $number;
}

class TestSoapServer
{
    /**
     * getAuthors
     *
     * @desc Get all authors
     * @return wrapper[] $authors @className=Test
     */
    public function getAuthors()
    {
        $authors = array(
            array('name' => 'john', 'number' => 123),
            array('name' => 'peter', 'number' => 456),
        );
        $result = array();
        foreach ($authors as $author) {
            $obj = new Test();
            $obj->name = $author['name'];
            $obj->number = $author['number'];
            $result[] = $obj;
        }
        return $result;
    }
}

Request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://foo.bar/testsoapserver">
<soapenv:Header/>
<soapenv:Body>
  <int1:getAuthors xmlns:int1="http://foo.bar/testsoapserver"/>
</soapenv:Body>
</soapenv:Envelope>

Response:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/wsdl-creator/examples/TestSoapServer.php" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <SOAP-ENV:Body>
      <ns1:getAuthorsResponse>
         <return SOAP-ENC:arrayType="SOAP-ENC:Struct[2]" xsi:type="SOAP-ENC:Array">
            <item xsi:type="SOAP-ENC:Struct">
               <name xsi:type="xsd:string">john</name>
               <number xsi:type="xsd:int">123</number>
            </item>
            <item xsi:type="SOAP-ENC:Struct">
               <name xsi:type="xsd:string">peter</name>
               <number xsi:type="xsd:int">456</number>
            </item>
         </return>
      </ns1:getAuthorsResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

So I receive correct array of objects (Test).

Testing at soapUI 4.5.2.

from wsdl-creator.

rhelms avatar rhelms commented on May 30, 2024

I was getting something like that at one stage, but I was expecting that
the tag should be an tag, or at least mention it
somewhere.

Though, it could be my relative inexperience with the full notation of the
soap definitions.

I'll try to get back to that point, and then validate the results against
the WSDL, using SoapUI when I get to work in 1 hour.

On Friday, May 23, 2014, Piotr Olaszewski [email protected] wrote:

I was try to implement your example:

$wsdl = new WSDLCreator('TestSoapServer', 'http://localhost/wsdl-creator/examples/TestSoapServer.php');$wsdl->setNamespace("http://foo.bar/");
if (isset($_GET['wsdl'])) {
$wsdl->renderWSDL();
exit;}
$wsdl->renderWSDLService();
$server = new SoapServer(null, array(
'uri' => 'http://localhost/wsdl-creator/examples/TestSoapServer.php'));$server->setClass('TestSoapServer');$server->handle();
class Test{
/** * @type string /
public $name;
/
* * @type int /
public $number;}
class TestSoapServer{
/
* * getAuthors * * @desc Get all authors * @return wrapper[] $authors @classname=Test */
public function getAuthors()
{
$authors = array(
array('name' => 'john', 'number' => 123),
array('name' => 'peter', 'number' => 456),
);
$result = array();
foreach ($authors as $author) {
$obj = new Test();
$obj->name = $author['name'];
$obj->number = $author['number'];
$result[] = $obj;
}
return $result;
}}

Request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://foo.bar/testsoapserver">
soapenv:Header/
soapenv:Body
<int1:getAuthors xmlns:int1="http://foo.bar/testsoapserver"/>
/soapenv:Body
/soapenv:Envelope

Response:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/wsdl-creator/examples/TestSoapServer.php" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
SOAP-ENV:Body
ns1:getAuthorsResponse


john
123


peter
456


/ns1:getAuthorsResponse
/SOAP-ENV:Body
/SOAP-ENV:Envelope

So I receive correct array of objects (Test).


Reply to this email directly or view it on GitHubhttps://github.com//issues/10#issuecomment-43930667
.

from wsdl-creator.

rhelms avatar rhelms commented on May 30, 2024

First thing I should note is that packagist seems to be a bit behind. 1.2 isn't available yet, and if I specify dev-master, it's still pointing to [https://github.com/piotrooo/wsdl-creator/commit/a1270060c660543191f7b88014d8203d73966941] from April 1. I've done a git merge and merge with origin to get to the latest master.

I had a bit more of a look, and there a couple of things that don't quite sit right with the response.

The first is that the namespace of the ns1:getAuthorsResponse tag does not match the namespace used in the request, and particularly the getAuthors tag. I would expect that this namespace should be http://foo.bar/testsoapserver. SoapUI will report line -1: Missing message wrapper element [http://foo.bar/testsoapserver@getAuthorsResponse
This can be resolved by specifying http://foo.bar/testsoapserver as the uri when creating the SoapServer.

Once this is done, the getAuthorsResponse will have the right namespace (i.e. matching the generated WSDL), and the next validation message is line -1: Missing message part [authors]. There's also a warning issued when playing the request: Fri May 23 09:33:00 EST 2014:WARN:Ignoring validation error: error: cvc-complex-type.3.2.2: Attribute not allowed: encodingStyle@http://schemas.xmlsoap.org/soap/envelope/ in element Envelope@http://schemas.xmlsoap.org/soap/envelope/, but I'm not going to be concerned with that for the moment.

According to the PHP documentation, 'uri' should be the namespace, and 'location' should be the physical URL that is expected to be called to access the service. Unfortunately, it's not until I specify the WSDL, so I get the tag. But I guess that's a part of why I'm using the WSDLCreator: to have a WSDL that Soap Clients can references and that PHP can build the correct XML against.

At this point, the response is back at what I had originally, but validation is Element not allowed: Struct@http://schemas.xmlsoap.org/soap/encoding/ for the <SOAP-ENC:Struct tags> where the tag should be. It's likely that the issue is with PHP rather than the WSDLCreator, but I'm going to do a bit more research into the definition of the xsd:complexType. That portion of the WSDL doesn't specify as the tag to use when representing the contents of the array.

   <xsd:complexType name="ArrayOfAuthors">
        <xsd:complexContent>
           <xsd:restriction base="soapenc:Array">
              <xsd:attribute ref="soapenc:arrayType" arrayType="ns:AppSoapAuthor[]"/>
           </xsd:restriction>
        </xsd:complexContent>
     </xsd:complexType>

So I'm going to see what can be done, so I can get <authors><author><id>.

Thanks for your help so far. I will update as I work out what is going on.

from wsdl-creator.

rhelms avatar rhelms commented on May 30, 2024

I did a bit more digging, and decided to see if I could manually update the WSDL to meet the goal. Using this post [http://stackoverflow.com/questions/2293873/how-do-i-define-an-array-of-custom-types-in-wsdl] as a guide, I made the following changes to the WSDL:

Old version:

  <xsd:schema targetNamespace="http://intalio-webservice.reubenh3.dev.otw.internal/app/soap/intaliowebservicesoapserver/types" xmlns="http://intalio-webservice.reubenh3.dev.otw.internal/app/soap/intaliowebservicesoapserver/types">
     <xsd:element name="AppSoapAuthor">
        <xsd:complexType>
           <xsd:sequence>
              <xsd:element name="id" type="xsd:int"/>
              <xsd:element name="name" type="xsd:string"/>
              <xsd:element name="created" type="xsd:string"/>
              <xsd:element name="modified" type="xsd:string"/>
           </xsd:sequence>
        </xsd:complexType>
     </xsd:element>
     <xsd:complexType name="ArrayOfAuthors">
        <xsd:complexContent>
           <xsd:restriction base="soapenc:Array">
              <xsd:attribute ref="soapenc:arrayType" arrayType="ns:AppSoapAuthor[]"/>
           </xsd:restriction>
        </xsd:complexContent>
     </xsd:complexType>
  </xsd:schema>

New version:

<xsd:schema targetNamespace="http://intalio-webservice.reubenh3.dev.otw.internal/app/soap/intaliowebservicesoapserver/types" xmlns="http://intalio-webservice.reubenh3.dev.otw.internal/app/soap/intaliowebservicesoapserver/types">
    <xsd:complexType name="AppSoapAuthor">
        <xsd:sequence>
            <xsd:element name="id" type="xsd:int"/>
            <xsd:element name="name" type="xsd:string"/>
            <xsd:element name="created" type="xsd:string"/>
            <xsd:element name="modified" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="AppSoapAuthor" nillable="true" type="ns:AppSoapAuthor" />

    <xsd:complexType name="ArrayOfAuthors">
        <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="unbounded" name="author" nillable="true" type="ns:AppSoapAuthor" />
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="ArrayOfAuthors" nillable="true" type="ns:ArrayOfAuthors" />
</xsd:schema>

Results in

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://intalio-webservice.reubenh3.dev.otw.internal/app/soap/intaliowebservicesoapserver">
<SOAP-ENV:Body>
  <ns1:getAuthorsResponse>
     <authors>
        <author>
           <id>1</id>
           <name>Doug Tidwell</name>
           <created/>
           <modified/>
        </author>
        <author>
           <id>2</id>
           <name>Reuben Helms</name>
           <created/>
           <modified/>
        </author>
     </authors>
  </ns1:getAuthorsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

This notation for complex type arrays allow me to specify the element name in the array, and successfully validates against the WSDL. However, I still need to specify the WSDL in the SoapServer, or PHP doesn't know enough information about those types to be able to generate the correct XML.

If it's okay with you, I'm going to attempt to make changes to use this notation when specifying complex arrays, and I'll submit a pull request when done. Something that would need to be done is deciding the notation to record the name of the element.

Currently, wrapper[] $authors @className=\App\Soap\Author is being used. Perhaps something like wrapper[] $authors @className=\App\Soap\Author @elementName=author could be used to specify the repeating element name, or a custom phpDoc tag called @element could be placed on the class to specify the element name (am I getting object[] and wrapper[] mixed up?).

from wsdl-creator.

rhelms avatar rhelms commented on May 30, 2024

It occurs to me that it might be easier to pluralize the name for array types, rather than add @elementName to the complexType definition.

So, instead of

wrapper[] $authors @className=\App\Soap\Author

or the proposed

wrapper[] $authors @className=\App\Soap\Author @elementName=author

we would just have

wrapper[] $author @className=\App\Soap\Author

Then this would automatically name the top element <authors> and the child elements <author>.

from wsdl-creator.

rhelms avatar rhelms commented on May 30, 2024

And then I noticed that you've got a depluralize function, so perhaps I could just depluralize the name of the array to set the child element name.

from wsdl-creator.

piotrooo avatar piotrooo commented on May 30, 2024

I was getting something like that at one stage, but I was expecting that the tag should be > an tag, or at least mention it somewhere.

Yea, I think this can be good improve - better understanding of response content.

1.2 isn't available yet, and if I specify dev-master, it's still pointing to [a127006] from April 1. I've
done a git merge and merge with origin to get to the latest master.

I thing something is wrong with packagist hook, I try to force update at packagist.

The first is that the namespace of the ns1:getAuthorsResponse tag does not match the
namespace used in the request, and particularly the getAuthors tag. I would expect that this
namespace should be http://foo.bar/testsoapserver. SoapUI will report line -1: Missing message
wrapper element [http://foo.bar/testsoapserver@getAuthorsResponse
This can be resolved by specifying http://foo.bar/testsoapserver as the uri when creating the
SoapServer.

You thing about it:
xmlns:int="http://foo.bar/testsoapserver" in request and this xmlns:ns1="http://localhost/wsdl-creator/examples/TestSoapServer.php" in response? If you that is a bug.

And then I noticed that you've got a depluralize function, so perhaps I could just depluralize the > name of the array to set the child element name.

Yes, depluralize is better option than passing another parameter to parse form phpDOC.

One question, currently I implemented in WSDL Creator some binding types as rpc/literal, rpc/encoded, document/literal wrapped - how your changes will affect these functionality?

from wsdl-creator.

rhelms avatar rhelms commented on May 30, 2024

I'm not sure about the different binding types. I will look them up, and make sure the types can be used with each.

from wsdl-creator.

piotrooo avatar piotrooo commented on May 30, 2024

OK. You know how fix namespace bug?

from wsdl-creator.

piotrooo avatar piotrooo commented on May 30, 2024

I found. In SoapServer need to set:

$server = new SoapServer(null, array(
    'uri' => 'http://foo.bar/testsoapserver',
    'location' => 'http://localhost/wsdl-creator/examples/TestSoapServer.php',
));

uri is corresponding with namespace generated in WSDL Creator. Maybe good option is write helper method to getting namespace.

from wsdl-creator.

piotrooo avatar piotrooo commented on May 30, 2024

I commit namespace fix. Now can create SoapServer:

$server = new SoapServer(null, array(
    'uri' => $wsdl->getNamespaceWithSanitizedClass(),
    'location' => 'http://localhost/wsdl-creator/examples/TestSoapServer.php',
));

from wsdl-creator.

piotrooo avatar piotrooo commented on May 30, 2024

To testing use dev-master.

from wsdl-creator.

rhelms avatar rhelms commented on May 30, 2024

With regards to the different document types, the generated requests changed quite a bit between the different types.

When does as RPCLiteral (default) a generated request looks like:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://intalio-webservice.reubenh3.dev.otw.internal/app/soap/intaliowebservicesoapserver" xmlns:typ="http://intalio-webservice.reubenh3.dev.otw.internal/app/soap/intaliowebservicesoapserver/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soapenv:Header/>
    <soapenv:Body>
        <int:getAuthors/>
    </soapenv:Body>
</soapenv:Envelope>

When does as RPC Encoded, the request is:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://intalio-webservice.reubenh3.dev.otw.internal/app/soap/intaliowebservicesoapserver" xmlns:typ="http://intalio-webservice.reubenh3.dev.otw.internal/app/soap/intaliowebservicesoapserver/types">
   <soapenv:Header/>
   <soapenv:Body>
      <int:getAuthors soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
   </soapenv:Body>
</soapenv:Envelope>

And with this example, when the WSDL is not specified on the SoapServer, the request is fine, and looks like Rpc Literal. However, when the WSDL is specified, there is a Soap Fault SOAP-ERROR: Parsing WSDL: Unspecified encodingStyle, so I must be missing something when creating the response, or there's something missing in the WSDL.

And lastly, here is Document Literal, which is completely different:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://intalio-webservice.reubenh3.dev.otw.internal/app/soap/intaliowebservicesoapserver/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:int="http://intalio-webservice.reubenh3.dev.otw.internal/app/soap/intaliowebservicesoapserver">
   <soapenv:Header/>
   <soapenv:Body>
      <typ:getAuthorsRequestParameters/>
   </soapenv:Body>
</soapenv:Envelope>

If I specify the WSDL, I get a PHP Fatal error when trying to handle the request SOAP-ERROR: Encoding: object has no &#039;authors&#039; property, and when there's no WSDL, I get this PHP Fatal Error Function &#039;getAuthorsRequestParameters&#039; doesn&#039;t exist. This seems to suggest that Document Literal is completely different to Rpc Literal, and more work would need to be done to see objects should be set up to handle those binding styles.

In the mean time, I've almost completed the work.

from wsdl-creator.

rhelms avatar rhelms commented on May 30, 2024

When using Rpc Encoded, you must specify encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" on the soap:body elements in operation. This will result in the types being explicitly defined in the response. This looks like a separate issue to my changes, so I might log another issue for this.

I'm about to head off home (Australian timezone), so I will contribute more to this on Monday, or if I get time, on the weekend.

from wsdl-creator.

piotrooo avatar piotrooo commented on May 30, 2024

OK, no problem, maybe I try implement something on the weekend - so look dev-master for new commits.

from wsdl-creator.

rhelms avatar rhelms commented on May 30, 2024

Fixed with pull request #13

from wsdl-creator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.