title: CXF Client - unexpected XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {null}html
body: <p>I am trying to call webservice with Apache CXF.</p>
  
  <p>I generated java classes from wsdl file located <a href="https://zsmopl.ezdrowie.gov.pl/cxf/zsmopl/ws/?wsdl" rel="nofollow noreferrer">here</a>.</p>
  
  <p>Here is my main method:</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
      ObslugaKomunikatowService service = new ObslugaKomunikatowService();
      ObslugaKomunikatow client = service.getObslugaKomunikatowPort();
      client.zapiszKomunikatZB(new KomunikatZBMT());
  }
  </code></pre>
  
  <p>This code crashes with this exception:</p>
  
  <pre><code>Exception in thread "main" com.sun.xml.internal.ws.protocol.soap.MessageCreationException: Couldn't create SOAP message due to exception: unexpected XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {null}html
      at com.sun.xml.internal.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:304)
      at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.createResponsePacket(HttpTransportPipe.java:268)
      at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:217)
      at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:130)
      at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:95)
      at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:1121)
      at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:1035)
      at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:1004)
      at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:862)
      at com.sun.xml.internal.ws.client.Stub.process(Stub.java:448)
      at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:178)
      at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
      at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:77)
      at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:147)
      at com.sun.proxy.$Proxy34.zapiszKomunikatZB(Unknown Source)
      at pl.opencare.zsmoplclient.ZSMOPLClient.main(ZSMOPLClient.java:98)
  Caused by: com.sun.xml.internal.ws.streaming.XMLStreamReaderException: unexpected XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {null}html
      at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.verifyTag(XMLStreamReaderUtil.java:261)
      at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:205)
      at com.oracle.webservices.internal.impl.encoding.StreamDecoderImpl.decode(StreamDecoderImpl.java:49)
      at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:234)
      at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:151)
      at com.sun.xml.internal.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:299)
      ... 15 more
  </code></pre>
  
  <p>There is generated service class:</p>
  
  <pre><code>package pl.gov.csioz.zsmopl.ws;
  
  import java.net.MalformedURLException;
  import java.net.URL;
  import javax.xml.namespace.QName;
  import javax.xml.ws.WebEndpoint;
  import javax.xml.ws.WebServiceClient;
  import javax.xml.ws.WebServiceFeature;
  import javax.xml.ws.Service;
  
  /**
   * This class was generated by Apache CXF 3.2.5
   * 2018-07-11T11:38:29.954+02:00
   * Generated source version: 3.2.5
   *
   */
  @WebServiceClient(name = "ObslugaKomunikatowService",
                    wsdlLocation = "file:ZSMOPL.wsdl",
                    targetNamespace = "http://csioz.gov.pl/zsmopl/ws/")
  public class ObslugaKomunikatowService extends Service {
  
      public final static URL WSDL_LOCATION;
  
      public final static QName SERVICE = new QName("http://csioz.gov.pl/zsmopl/ws/", "ObslugaKomunikatowService");
      public final static QName ObslugaKomunikatowPort = new QName("http://csioz.gov.pl/zsmopl/ws/", "ObslugaKomunikatowPort");
      static {
          URL url = null;
          try {
              url = new URL("file:ZSMOPL.wsdl");
          } catch (MalformedURLException e) {
              java.util.logging.Logger.getLogger(ObslugaKomunikatowService.class.getName())
                  .log(java.util.logging.Level.INFO,
                       "Can not initialize the default wsdl from {0}", "file:ZSMOPL.wsdl");
          }
          WSDL_LOCATION = url;
      }
  
      public ObslugaKomunikatowService(URL wsdlLocation) {
          super(wsdlLocation, SERVICE);
      }
  
      public ObslugaKomunikatowService(URL wsdlLocation, QName serviceName) {
          super(wsdlLocation, serviceName);
      }
  
      public ObslugaKomunikatowService() {
          super(WSDL_LOCATION, SERVICE);
      }
  
      public ObslugaKomunikatowService(WebServiceFeature ... features) {
          super(WSDL_LOCATION, SERVICE, features);
      }
  
      public ObslugaKomunikatowService(URL wsdlLocation, WebServiceFeature ... features) {
          super(wsdlLocation, SERVICE, features);
      }
  
      public ObslugaKomunikatowService(URL wsdlLocation, QName serviceName, WebServiceFeature ... features) {
          super(wsdlLocation, serviceName, features);
      }
  
  
  
  
      /**
       *
       * @return
       *     returns ObslugaKomunikatow
       */
      @WebEndpoint(name = "ObslugaKomunikatowPort")
      public ObslugaKomunikatow getObslugaKomunikatowPort() {
          return super.getPort(ObslugaKomunikatowPort, ObslugaKomunikatow.class);
      }
  
      /**
       *
       * @param features
       *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the &lt;code&gt;features&lt;/code&gt; parameter will have their default values.
       * @return
       *     returns ObslugaKomunikatow
       */
      @WebEndpoint(name = "ObslugaKomunikatowPort")
      public ObslugaKomunikatow getObslugaKomunikatowPort(WebServiceFeature... features) {
          return super.getPort(ObslugaKomunikatowPort, ObslugaKomunikatow.class, features);
      }
  
  }
  </code></pre>
  
  <p>There is generted port class:</p>
  
  <pre><code>package pl.gov.csioz.zsmopl.ws;
  
  import javax.jws.WebMethod;
  import javax.jws.WebParam;
  import javax.jws.WebResult;
  import javax.jws.WebService;
  import javax.xml.bind.annotation.XmlSeeAlso;
  import javax.xml.ws.RequestWrapper;
  import javax.xml.ws.ResponseWrapper;
  
  /**
   * This class was generated by Apache CXF 3.2.5
   * 2018-07-11T11:38:29.942+02:00
   * Generated source version: 3.2.5
   *
   */
  @WebService(targetNamespace = "http://csioz.gov.pl/zsmopl/ws/", name = "ObslugaKomunikatow")
  @XmlSeeAlso({pl.gov.csioz.zsmopl.ws.obslugakomunikatow.ObjectFactory.class, pl.gov.csioz.zsmopl.mt.ObjectFactory.class})
  public interface ObslugaKomunikatow {
  
      @WebMethod(action = "zapiszKomunikatZB")
      @RequestWrapper(localName = "zapiszKomunikatZB", targetNamespace = "http://csioz.gov.pl/zsmopl/ws/obslugakomunikatow/", className = "pl.gov.csioz.zsmopl.ws.obslugakomunikatow.ZapiszKomunikatZB")
      @ResponseWrapper(localName = "zapiszKomunikatZBResponse", targetNamespace = "http://csioz.gov.pl/zsmopl/ws/obslugakomunikatow/", className = "pl.gov.csioz.zsmopl.ws.obslugakomunikatow.ZapiszKomunikatZBResponse")
      @WebResult(name = "identyfikatorKomunikatu", targetNamespace = "")
      public pl.gov.csioz.zsmopl.mt.IdentyfikatorKomunikatuMT zapiszKomunikatZB(
          @WebParam(name = "komunikatZB", targetNamespace = "")
          pl.gov.csioz.zsmopl.mt.KomunikatZBMT komunikatZB
      ) throws BladTworzeniaIdentyfikatoraKomunikatu, BladDostepnosci;
  
      @WebMethod(action = "zapiszKomunikatOS")
      @RequestWrapper(localName = "zapiszKomunikatOS", targetNamespace = "http://csioz.gov.pl/zsmopl/ws/obslugakomunikatow/", className = "pl.gov.csioz.zsmopl.ws.obslugakomunikatow.ZapiszKomunikatOS")
      @ResponseWrapper(localName = "zapiszKomunikatOSResponse", targetNamespace = "http://csioz.gov.pl/zsmopl/ws/obslugakomunikatow/", className = "pl.gov.csioz.zsmopl.ws.obslugakomunikatow.ZapiszKomunikatOSResponse")
      @WebResult(name = "identyfikatorKomunikatu", targetNamespace = "")
      public pl.gov.csioz.zsmopl.mt.IdentyfikatorKomunikatuMT zapiszKomunikatOS(
          @WebParam(name = "komunikatOS", targetNamespace = "")
          pl.gov.csioz.zsmopl.mt.KomunikatOSMT komunikatOS
      ) throws BladTworzeniaIdentyfikatoraKomunikatu, BladDostepnosci;
  
      @WebMethod(action = "zapiszKomunikatPD")
      @RequestWrapper(localName = "zapiszKomunikatPD", targetNamespace = "http://csioz.gov.pl/zsmopl/ws/obslugakomunikatow/", className = "pl.gov.csioz.zsmopl.ws.obslugakomunikatow.ZapiszKomunikatPD")
      @ResponseWrapper(localName = "zapiszKomunikatPDResponse", targetNamespace = "http://csioz.gov.pl/zsmopl/ws/obslugakomunikatow/", className = "pl.gov.csioz.zsmopl.ws.obslugakomunikatow.ZapiszKomunikatPDResponse")
      @WebResult(name = "identyfikatorKomunikatu", targetNamespace = "")
      public pl.gov.csioz.zsmopl.mt.IdentyfikatorKomunikatuMT zapiszKomunikatPD(
          @WebParam(name = "komunikatPD", targetNamespace = "")
          pl.gov.csioz.zsmopl.mt.KomunikatPDMT komunikatPD
      ) throws BladTworzeniaIdentyfikatoraKomunikatu, BladDostepnosci;
  }
  </code></pre>
  
  <p>And generated class that I am trying to send:</p>
  
  <pre><code>package pl.gov.csioz.zsmopl.mt;
  
  import java.util.ArrayList;
  import java.util.List;
  import javax.xml.bind.annotation.XmlAccessType;
  import javax.xml.bind.annotation.XmlAccessorType;
  import javax.xml.bind.annotation.XmlElement;
  import javax.xml.bind.annotation.XmlType;
  
  
  /**
   * Komunikat zg�oszenia brak�w.
   *             
   * 
   * &lt;p&gt;Java class for KomunikatZBMT complex type.
   * 
   * &lt;p&gt;The following schema fragment specifies the expected content contained within this class.
   * 
   * &lt;pre&gt;
   * &amp;lt;complexType name="KomunikatZBMT"&amp;gt;
   *   &amp;lt;complexContent&amp;gt;
   *     &amp;lt;extension base="{http://csioz.gov.pl/zsmopl/mt/}KomunikatMT"&amp;gt;
   *       &amp;lt;sequence&amp;gt;
   *         &amp;lt;element name="idMPDPodmiotuRaportujacego" type="{http://csioz.gov.pl/zsmopl/mt/}IdentyfikatorMPDPodmiotuMT"/&amp;gt;
   *         &amp;lt;element name="komunikatTransakcja" type="{http://csioz.gov.pl/zsmopl/mt/}KomunikatTransakcjaZBMT" maxOccurs="unbounded"/&amp;gt;
   *       &amp;lt;/sequence&amp;gt;
   *     &amp;lt;/extension&amp;gt;
   *   &amp;lt;/complexContent&amp;gt;
   * &amp;lt;/complexType&amp;gt;
   * &lt;/pre&gt;
   * 
   * 
   */
  @XmlAccessorType(XmlAccessType.FIELD)
  @XmlType(name = "KomunikatZBMT", propOrder = {
      "idMPDPodmiotuRaportujacego",
      "komunikatTransakcja"
  })
  public class KomunikatZBMT
      extends KomunikatMT
  {
  
      @XmlElement(required = true)
      protected IdentyfikatorMPDPodmiotuMT idMPDPodmiotuRaportujacego;
      @XmlElement(required = true)
      protected List&lt;KomunikatTransakcjaZBMT&gt; komunikatTransakcja;
  
      /**
       * Gets the value of the idMPDPodmiotuRaportujacego property.
       * 
       * @return
       *     possible object is
       *     {@link IdentyfikatorMPDPodmiotuMT }
       *     
       */
      public IdentyfikatorMPDPodmiotuMT getIdMPDPodmiotuRaportujacego() {
          return idMPDPodmiotuRaportujacego;
      }
  
      /**
       * Sets the value of the idMPDPodmiotuRaportujacego property.
       * 
       * @param value
       *     allowed object is
       *     {@link IdentyfikatorMPDPodmiotuMT }
       *     
       */
      public void setIdMPDPodmiotuRaportujacego(IdentyfikatorMPDPodmiotuMT value) {
          this.idMPDPodmiotuRaportujacego = value;
      }
  
      /**
       * Gets the value of the komunikatTransakcja property.
       * 
       * &lt;p&gt;
       * This accessor method returns a reference to the live list,
       * not a snapshot. Therefore any modification you make to the
       * returned list will be present inside the JAXB object.
       * This is why there is not a &lt;CODE&gt;set&lt;/CODE&gt; method for the komunikatTransakcja property.
       * 
       * &lt;p&gt;
       * For example, to add a new item, do as follows:
       * &lt;pre&gt;
       *    getKomunikatTransakcja().add(newItem);
       * &lt;/pre&gt;
       * 
       * 
       * &lt;p&gt;
       * Objects of the following type(s) are allowed in the list
       * {@link KomunikatTransakcjaZBMT }
       * 
       * 
       */
      public List&lt;KomunikatTransakcjaZBMT&gt; getKomunikatTransakcja() {
          if (komunikatTransakcja == null) {
              komunikatTransakcja = new ArrayList&lt;KomunikatTransakcjaZBMT&gt;();
          }
          return this.komunikatTransakcja;
      }
  
  }
  </code></pre>
  
  <p>Do you know what's causing this exception?</p>