goetas-webservices / soap-client

PHP implementation of SOAP 1.1 and 1.2 client specifications
MIT License
175 stars 28 forks source link

Adding xmlns:xsi XMLSchema-instance #36

Open mdesign83 opened 5 years ago

mdesign83 commented 5 years ago

Hi,

I would like to port my SoapClient code to goetas-webservices but I'm running a problem where the server requires xsi:type attribute on the record. How can I add these type attributes to the generated xml request?

Thanks, Karoly

mdesign83 commented 5 years ago

I would like to achieve this:

<?xml version="1.0" ?>
<Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <Name>Fred</Name> 
    <HomeAddress xsi:type="USAddressType"> 
        <Line1>234 Lancaseter Av</Line1> 
        <Line2>SmallsVille</Line2> 
        <State>Florida</State> 
        <Zipcode>34543</Zipcode> 
    </HomeAddress> 
</Person>

https://www.liquid-technologies.com/xml-schema-tutorial/xsd-extending-types

goetas commented 5 years ago

From the readme of this project:

Only document/literal style is supported and the webservice should follow the WS-I guidelines.

Im not sure if the XMLSchema-instance usage you are tying is WS-I and document/literal style compliant

mdesign83 commented 5 years ago

I found a solution which works for me: [https://github.com/schmittjoh/serializer/issues/433#issuecomment-324246156](). I modified the listener to a subscriber and then I can inject it before building the serializer:

$serializer = SoapContainerBuilder::createSerializerBuilderFromContainer($container, null, SoapClientContainer::getMetadataDir());
$serializer->configureListeners(function(EventDispatcher $handlerBuilder) {
    $jmsXsi = new JmsXsiTypeSubscriber(
        [
            'namespace' => 'http://schemas.datacontract.org/...',
            'type'      => 'DummyType',
            'class'     => DummyType::class,
        ], [
              //...
        ]
    );
    $handlerBuilder->addSubscriber($jmsXsi);
});
$serializer = $serializer->build();

Any advice is welcome.

goetas commented 5 years ago

Well, it might work... but you did not answer to my previous comment:

Im not sure if the XMLSchema-instance usage you are tying is WS-I and document/literal style compliant

mdesign83 commented 5 years ago

I'm affraid it's not. It is RPC/encoded, so "Although it is legal WSDL, RPC/encoded is not WS-I compliant." [https://www.ibm.com/developerworks/library/ws-whichwsdl/]()