2

I'm currently developing client app using official API of Polish Ministry of Finance to check NIP numbers. (https://sprawdz-status-vat.mf.gov.pl/?wsdl) Unfortunately I have a problem with wsdl published by them. Namely there is a message with 2 parts.

<wsdl:message name="SprawdzNIPNaDzienZapytanie">
    <wsdl:part name="NIP" element="tns:NIP"/>
    <wsdl:part name="Data" element="tns:Data"/>
</wsdl:message>

I was trying to parse it by wsimport maven plugin but client side code didn't even generate, because of error

[ERROR] operation "SprawdzNIPNaDzien": more than one part bound to body[ERROR] operation "SprawdzNIPNaDzien": more than one part bound to body

I thought ok, I will try different tool for generating code. As I have already used cxf earlier I chose to use it. Code generated just fine but when I was trying to call the service I did get similar error as before.

SEI WeryfikacjaVAT has method sprawdzNIPNaDzien annotated as BARE but it has more than one parameter bound to body. This is invalid. Please annotate the method with annotation: @SOAPBinding(parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)

Now I'm wondering. Is there a way to make it work without changing wsdl file? As it is official API which doesn't belong to me, I have no way to correct it. I guess there must by a way to operate with such wsdl as SoapUI handle it just fine and doesn't throw any errors.

@Update

I have tried to add cxf parameter mentioned by Khalid so my pom.xml looks as follows:

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>${cxf.version}</version>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
                <defaultOptions>
                </defaultOptions>
                <sourceRoot>${project.build.directory}/generated-sources/cxf</sourceRoot>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>other.xml</wsdl>
                    </wsdlOption>
                    <wsdlOption>
                        <wsdl>${basedir}/src/main/resources/wsdl/my.wsdl</wsdl>
                        <bindingFiles>
                            <bindingFile>
                                ${basedir}/src/main/resources/wsdl/bindings.xml
                            </bindingFile>
                        </bindingFiles>
                        <noAddressBinding>true</noAddressBinding>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

And bindings.xml file:

<jaxws:bindings
        wsdlLocation="my.wsdl"
        xmlns="http://java.sun.com/xml/ns/jaxws"
        xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
    <enableWrapperStyle>true</enableWrapperStyle>
</jaxws:bindings>

Unfortunately port is still generated with @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) instead of WRAPPED annotation.

Dcortez
  • 3,716
  • 1
  • 23
  • 29

1 Answers1

1

When parameterStyle is Bare, web methods should only have 1 parameter.

With document style web services, the BP mandates that each message have zero or one part.

Here is an example :

<message name = "SubmitPurchaseOrderMessage">
    <part name="Order" element "sd:purchaseOrder"/>
</message>

So, that means the parameters are all inside element in the SOAP request.

  • When the parameter style is wrapped, that makes sense to have all parameters wrapped inside element.
  • When the parameter style is bare, all parameters are not wrapped inside any element.

Therefore, that makes sense to have this under doc/lit/bare:

<message name="add">
       <part name="parameter1" element="tns:a"/>
 </message>

The schema will show something like this:

<add>
   <element name="parameter1" type:int/>
</add>

But that won't make sense to have this message under doc/lit/bare:

<message name="add>
       <part name = "parameter1" element="tns:a"/>
       <part name = "parameter2" element="tns:b"/>
</message>

This is not valid as BP mandates that with document style web service, the message must have at most 1 element.

That's the reason your web method won't deploy. you have more than one part in message. Reference : https://coderanch.com/t/624936/certification/parameterStyle-Bare-web-methods-parameter

if you want to make it wrapped style without changing wsdl file then you use binding file with cxf to generate code.

Here is the bindings.xml

<jaxws:bindings
  wsdlLocation="Your wsdl file path"
  xmlns="http://java.sun.com/xml/ns/jaxws"
  xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
  <enableWrapperStyle>true</enableWrapperStyle>
</jaxws:bindings>

enableWrapperStyle = false to generate unwrapped style code.

and Here is the configuration you'll in pom.xml

<configuration>
  <!-- Binding file for Wrapped style services  -->
      <defaultOptions>
          <bindingFiles>                     
              <bindingFile>
                  ${basedir}/src/main/resources/bindings.xml
              </bindingFile>
           </bindingFiles>
           <noAddressBinding>true</noAddressBinding>
       </defaultOptions>
 </configuration>
Khalid Shah
  • 3,132
  • 3
  • 20
  • 39
  • Hey! Take a look at updated question. Gave it a try but unfortunately it didn't solve my issue. – Dcortez Apr 30 '18 at 05:06
  • BARE webservices are generated when the 'operation' name, the 'message' name and the 'element' name are different in some shape or form. To auto generate your client or service stubs as WRAPPED, all of those three elements must be the same. your names are different in .wsdl file. Change your .wsdl file accordingly so that its 'operation' name, the 'message' name and the 'element' name are same then CXF will generate in Wrapped Style. Have you tried after manually changing the port type to WRAPPED and deploying the service? may be it helps but i am not sure about that. – Khalid Shah May 02 '18 at 09:51
  • [Have a look at this](https://stackoverflow.com/questions/21191079/when-to-use-soapbinding-parameterstyle-bare-and-soapbinding-parameterstyle-wrapp/21201469) – Khalid Shah May 02 '18 at 09:54
  • Changing wsdl file is not an option as this file does not belong to me. If I would like to change it manually it would require acknowledging whole team with the thing I have done, so when the new api version will be published (so will new wsdl file) will come out, someone will know what to do. I guess I can write to api maintainer if they are aware that wsdl is not correct. – Dcortez Jun 04 '18 at 14:44