title: SOAP response class not assigned (nil)
body: <p>I am using Delphi 10.2.3 to consume a SOAP web service. My problem is web service replies are not assigned to response classes defined in wsdl generated using <code>WSDLImp.exe</code>.</p>
  
  <p>I see that raw response XML contains all information in it as can be seen below:</p>
  
  <pre><code>HTTP/1.1 200
  X-HP-CAM-COLOR: V=1;ServerAddr=5F+cgNOCZPdfvCQ4naSfjw==;GUID=1|xpjJ6o0v_kd3rKz0c1ASIUXW--xZpHqeH8lJ3S2l30SxOi2DzpzfGfLpdqdxt0lg|L2VhcnNpdi93cy9FYXJzaXZXZWJTZXJ2aWNl
  Content-Type: text/xml;charset=utf-8
  Transfer-Encoding: chunked
  Date: Wed, 24 Oct 2018 15:54:46 GMT
  Server: EARSIV
  Strict-Transport-Security: max-age=157680000
  Set-Cookie: cookiesession1=1BEDB4A4PX73WJCTCIRPOUP46FNNFC28;Path=/;HttpOnly
  
  1da
  &lt;?xml version="1.0" ?&gt;&lt;S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;S:Body&gt;&lt;ns2:faturaOlusturResponse xmlns:ns2="http://service.earsiv.uut.cs.com.tr/"&gt;&lt;return xmlns=""&gt;&lt;resultCode&gt;AE00067&lt;/resultCode&gt;&lt;resultExtra&gt;&lt;/resultExtra&gt;&lt;resultText&gt;Web servis çağrısı "input" alanından gerekli bilgiler elde edilemedi. Eksik alanlar: null bu alan(lar)ın boş olmadığından emin olunuz!&lt;/resultText&gt;&lt;/return&gt;&lt;/ns2:faturaOlusturResponse&gt;&lt;/S:Body&gt;&lt;/S:Envelope&gt;
  0
  </code></pre>
  
  <p><code>return</code> in <code>faturaOlusturResponse</code> is <code>nil</code> as I see while debugging. Trying to access to <code>return.resultCode</code> raises an access violation.</p>
  
  <p>What you see is correct that there are garbage chars just before the line XML starts and right after it. I suspected that maybe the reason.</p>
  
  <p>But;</p>
  
  <p>1- I see <a href="https://www.telerik.com/fiddler" rel="nofollow noreferrer">Fiddler</a> has no problem parsing this and displaying formatted XML view with all correct information.</p>
  
  <p>2- I tried to use <code>OnAfterExecute()</code> event of <code>THTTPRIO</code>. I see that <code>SOAPResponse.Size</code> is 474 which is equal to XML line length in above raw response.</p>
  
  <p>I cannot think of what maybe the problem and could not fix it. Internet searches did not help.</p>
  
  <p>Any help is appreciated.</p>
  
  <p>Thanks.</p>
  
  <p>WSDL URL: <a href="https://earsiv.efinans.com.tr/earsiv/ws/EarsivWebService?wsdl" rel="nofollow noreferrer">https://earsiv.efinans.com.tr/earsiv/ws/EarsivWebService?wsdl</a></p>
  
  <p><strong>EDIT:</strong>
  Consuming web service method is done using <code>AFaturaOlustur()</code> function below. There is <code>SetSecurityHeader()</code> procedure which requires another unit code. I did not include them all not to post a lot of code in here. Json routines are from <a href="https://synopse.info/fossil/wiki/Synopse+OpenSource" rel="nofollow noreferrer">mORMot</a> framework. There are some constants used in some parts of the code as well. When I read file <code>response.xml</code> written in <code>HTTPRIO1AfterExecute()</code> procedure after running function, there is complete xml. It is identical to the one in raw response above:</p>
  
  <pre><code>class procedure TMyType.HTTPRIO1AfterExecute(const MethodName: string; SOAPResponse: TStream);
  var
    List: TStringList;
  begin
    List := TStringList.Create();
    try
      SOAPResponse.Position := 0;
      List.LoadFromStream(SOAPResponse);
      List.SaveToFile('response.xml');
    finally
      List.Free();
    end;
  end;
  
  function AFaturaOlustur(const Input: TFaturaOlusturInput; const GidenBelgeFormati: TGidenBelgeFormatlari; const GidenDosya, GelenDosya: string): Boolean;
  var
    RIO: THTTPRIO;
    WS: EarsivWebService;
    Request: faturaOlustur;
    Response: faturaOlusturResponse;
    Json: RawUTF8;
  begin
    if not TFile.Exists(GidenDosya) then
    begin
      LastError := 'AFaturaOlustur(): GidenDosya mevcut değil!';
    end;
  
    RIO := THTTPRIO.Create(nil);
    RIO.OnAfterExecute := TMyType.HTTPRIO1AfterExecute;
    RIO.URL := URLEArsivFatura;
    WS := (RIO as EarsivWebService);
    SetSecurityHeader(WS);
  
    Json := RecordSaveJSON(Input, TypeInfo(TFaturaOlusturInput));
  
    Request := nil;
    Response := nil;
    try
      Request := faturaOlustur.Create();
      Request.input := string(Json);
      Request.fatura := belge.Create();
      case GidenBelgeFormati of
        UBL: Request.fatura.belgeFormati := belgeFormatiEnum.UBL;
        CSXML: Request.fatura.belgeFormati := belgeFormatiEnum.CSXML;
        HTML: Request.fatura.belgeFormati := belgeFormatiEnum.HTML;
        PDF: Request.fatura.belgeFormati := belgeFormatiEnum.PDF;
        CUSTOM: Request.fatura.belgeFormati := belgeFormatiEnum.CUSTOM;
        PDF_CUSTOM: Request.fatura.belgeFormati := belgeFormatiEnum.PDF_CUSTOM;
        PDF_UBL: Request.fatura.belgeFormati := belgeFormatiEnum.PDF_UBL;
        CSXML1: Request.fatura.belgeFormati := belgeFormatiEnum.CSXML1;
        CSXML2: Request.fatura.belgeFormati := belgeFormatiEnum.CSXML2;
        CSXML3: Request.fatura.belgeFormati := belgeFormatiEnum.CSXML3;
        PDF_CSXML1: Request.fatura.belgeFormati := belgeFormatiEnum.PDF_CSXML1;
        PDF_CSXML2: Request.fatura.belgeFormati := belgeFormatiEnum.PDF_CSXML2;
        PDF_CSXML3: Request.fatura.belgeFormati := belgeFormatiEnum.PDF_CSXML3;
      end;
      Request.fatura.belgeIcerigi := ToByteDynArray(TFile.ReadAllBytes(GidenDosya));
  
      try
        Response := WS.faturaOlustur(Request);
      except
        on E: Exception do
        begin
          LastError := 'AFaturaOlustur(): ' + E.Message;
          Exit(False);
        end;
      end;
      Result := Assigned(Response.return);
      if Result then Result := Response.return.resultCode = rcSuccess;
      if Result then
      begin
        TFile.WriteAllBytes(GelenDosya, ToBytes(Response.output.belgeIcerigi));
      end
      else
      begin
        LastError := 'AFaturaOlustur(): ' + Response.return.resultText;
      end;
    finally
      Request.Free();
      Response.Free();
    end;
  end;
  </code></pre>