title: Error occurred while buffering incoming SOAP message using Metro client
body: <p>I am using <a href="http://metro.java.net/" rel="nofollow">Metro 2</a> client to consume the "Secure wcf web service in Java". But Metro client does not gives any response and stay in <em>hang</em> mode after very long time it produce the output as an error:</p>
  
  <p>Stack Trace:</p>
  
  <pre><code>SEVERE: WSSMSG0001: Error occurred while buffering incoming SOAP message.
  com.ctc.wstx.exc.WstxParsingException: Illegal character entity: expansion character (code 0x1a
   at [row,col {unknown-source}]: [1,6396222]
      at com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:606)
      at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:479)
      at com.ctc.wstx.sr.StreamScanner.reportIllegalChar(StreamScanner.java:2442)
      at com.ctc.wstx.sr.StreamScanner.validateChar(StreamScanner.java:2389)
      at com.ctc.wstx.sr.StreamScanner.resolveCharEnt(StreamScanner.java:2355)
      at com.ctc.wstx.sr.StreamScanner.fullyResolveEntity(StreamScanner.java:1501)
      at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2726)
      at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1065)
      at com.sun.xml.ws.util.xml.XMLStreamReaderToXMLStreamWriter.bridge(XMLStreamReaderToXMLStreamWriter.java:142)
      at com.sun.xml.ws.message.stream.StreamMessage.writePayloadTo(StreamMessage.java:376)
      at com.sun.xml.ws.message.stream.StreamMessage.writeEnvelope(StreamMessage.java:412)
      at com.sun.xml.ws.message.stream.StreamMessage.writeTo(StreamMessage.java:390)
      at com.sun.xml.ws.security.message.stream.LazyStreamBasedMessage.readMessage(LazyStreamBasedMessage.java:476)
      at com.sun.xml.wss.jaxws.impl.SecurityTubeBase.verifyInboundMessage(SecurityTubeBase.java:444)
      at com.sun.xml.wss.jaxws.impl.SecurityClientTube.processClientResponsePacket(SecurityClientTube.java:434)
      at com.sun.xml.wss.jaxws.impl.SecurityClientTube.processResponse(SecurityClientTube.java:362)
      at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:972)
      at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:910)
      at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:873)
      at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:775)
      at com.sun.xml.ws.client.Stub.process(Stub.java:429)
      at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:168)
      at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:119)
      at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:102)
      at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:151)
      at $Proxy44.pullCustomers(Unknown Source)
      at com.tekriti.client.Client.test(Client.java:106)
      at com.tekriti.client.Client.main(Client.java:44)
  com.sun.xml.ws.encoding.soap.DeserializationException: Failed to read a response: javax.xml.bind.UnmarshalException
   - with linked exception:
  [javax.xml.stream.XMLStreamException: Internal XSB error: Invalid State=0]
      at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:141)
      at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:102)
      at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:151)
      at $Proxy44.pullCustomers(Unknown Source)
      at com.tekriti.client.Client.test(Client.java:106)
      at com.tekriti.client.Client.main(Client.java:44)
  Caused by: javax.xml.bind.UnmarshalException
  </code></pre>
  
  <p>I am trying to fix this issue but no luck, Metro client is unable to parse the SOAP response in a correct way. I don't know where I am doing mistake or I have to use something else.<br>
  I am using <em>Netbeans 7.1</em> and <em>Metro 2.2</em>.  </p>
  
  <p>Please give your suggestions or if you had such problem in your past please do share with me.</p>
  
  <p><strong>updated</strong>:</p>
  
  <p>This is working fine:</p>
  
  <pre><code>     Dispatch&lt;Source&gt; sourceDispatch = null;
       sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.MESSAGE);
  
       ((BindingProvider)sourceDispatch).getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, "http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullCustomers");
      ((BindingProvider)sourceDispatch).getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, true);
     Source result = sourceDispatch.invoke(new StreamSource(new StringReader(req)));
  </code></pre>
  
  <p><code>req</code> contains the below one:</p>
  
  <pre><code>&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;s:Header&gt;
          &lt;Action&gt;http://cdx.dealerbuilt.com/Api/0.97/IStandardApi/PullCustomers&lt;/Action&gt;
      &lt;/s:Header&gt;
      &lt;s:Body&gt;
          &lt;PullCustomers xmlns="http://cdx.dealerbuilt.com/Api/0.97/"&gt;
              &lt;searchCriteria xmlns:d4p1="http://schemas.datacontract.org/2004/07/DealerBuilt.BaseApi" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
                  &lt;d4p1:ActivityStoreIds xmlns:d5p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"&gt;
                      &lt;d5p1:long&gt;64&lt;/d5p1:long&gt; 
                  &lt;/d4p1:ActivityStoreIds&gt;
  
                  &lt;d4p1:EnvironmentIds xmlns:d5p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"&gt; 
                      &lt;d5p1:long&gt;27&lt;/d5p1:long&gt;      
                  &lt;/d4p1:EnvironmentIds&gt;
              &lt;/searchCriteria&gt;
          &lt;/PullCustomers&gt;
      &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;
  </code></pre>
  
  <p>But it produces <code>Source</code> in output and takes SOAP envelope in request.</p>
  
  <p>I Need this should be work.</p>
  
  <pre><code>   org.tempuri.StandardApi service = new org.tempuri.StandardApi();
     CustomerSearchCriteriaType criteriaType = new CustomerSearchCriteriaType();
  
     QName environmentQName = new QName("http://schemas.datacontract.org/2004/07/DealerBuilt.BaseApi", "EnvironmentIds");
     ArrayOflong arrayOflong = new ArrayOflong();
     arrayOflong.getLong().add(27l);
     JAXBElement&lt;ArrayOflong&gt; environmentIds = new JAXBElement&lt;ArrayOflong&gt;(environmentQName, ArrayOflong.class, arrayOflong);
     criteriaType.setEnvironmentIds(environmentIds);
  
     QName activityQName = new QName("http://schemas.datacontract.org/2004/07/DealerBuilt.BaseApi", "ActivityStoreIds");
     ArrayOflong arrayOfActivity = new ArrayOflong();
     arrayOfActivity.getLong().add(64l);
     JAXBElement&lt;ArrayOflong&gt; activityIds = new JAXBElement&lt;ArrayOflong&gt;(activityQName, ArrayOflong.class, arrayOfActivity);
     criteriaType.setActivityStoreIds(activityIds);
  
     ArrayOfCustomerType customers = service.getCustomBindingIStandardApi().pullCustomers(criteriaType);
     if (customers != null) {
         System.out.println("Size of Customers::::" + customers.getCustomer().size());
     }
  </code></pre>
  
  <p>Request contains </p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;soapenv:Body&gt;
          &lt;PullCustomers xmlns="http://cdx.dealerbuilt.com/Api/0.97/"&gt;
              &lt;searchCriteria&gt;
                  &lt;ActivityStoreIds xmlns="http://schemas.datacontract.org/2004/07/DealerBuilt.BaseApi"&gt;
                      &lt;long xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays"&gt;64&lt;/long&gt;
                  &lt;/ActivityStoreIds&gt;
                  &lt;EnvironmentIds xmlns="http://schemas.datacontract.org/2004/07/DealerBuilt.BaseApi"&gt;
                      &lt;long xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays"&gt;27&lt;/long&gt;
                  &lt;/EnvironmentIds&gt;
              &lt;/searchCriteria&gt;
          &lt;/PullCustomers&gt;
      &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>But it hangs while producing output and after very long time it produce the error mentioned above.</p>
  
  <p>Is the difference between the requests causes the problem or something else?</p>