Jump to content
Stéphane Wierzbicki

Need help adding namespaces to SOAP

Recommended Posts

Good morning,

 

I have difficulties consuming a SOAP Web Service (obviously developed in C#). I managed to create the different Delphi classes via the WDSL import wizard. 

Unfortunately the request sent is not correctly formatted when generated by Delphi.


I don't have any problems when I run my tests via SOAPUI.

I have attached the two XML requests (the expected format generated by SOAPUI and the one generated by Delphi).


I could see that the namespaces were not added to the different XML nodes/properties.

 

Delphi generated SOAP Request 

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SOAP-ENV:Body>
    <Invocar xmlns="http://www.smart-ix.com/SXAPI/">
      <contexto>
        <CodNegocio>BUI</CodNegocio>
        <CodSistema>BUI</CodSistema>
        <Token/>
        <Usuario/>
      </contexto>
      <request>
        <Formulario>
          <VariableCircuitoConsultaInDTO>
            <Codigo>From</Codigo>
            <Valor>20190122</Valor>
          </VariableCircuitoConsultaInDTO>
          <VariableCircuitoConsultaInDTO>
            <Codigo>To</Codigo>
            <Valor>20190522</Valor>
          </VariableCircuitoConsultaInDTO>
        </Formulario>
        <Comando>Reporte_5</Comando>
        <Paginacion>
          <NroPagina>0</NroPagina>
          <RegistrosPorPagina>1</RegistrosPorPagina>
          <RetornaTotalRegistros>false</RetornaTotalRegistros>
        </Paginacion>
        <QuerySettings>
          <Paging>
            <PageNumber>1</PageNumber>
            <PageSize>1</PageSize>
            <TotalElements>1</TotalElements>
            <TotalPages>0</TotalPages>
          </Paging>
        </QuerySettings>
        <ReportCode>Reporte_5</ReportCode>
      </request>
    </Invocar>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

 

SOAPUI SOAP Envelope (good)

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sxap="http://www.blablabla.com/SXAPI/" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:apis="http://schemas.datacontract.org/2004/07/APISX.Contracts.Query.Models">
   <soapenv:Header/>
   <soapenv:Body>
      <sxap:Invocar>
         <!--Optional:-->
         <sxap:contexto>
	        <sxap:CodNegocio>BUI</sxap:CodNegocio>
	        <sxap:CodSistema>BUI</sxap:CodSistema>
	        <sxap:CodProducto></sxap:CodProducto>
	        <sxap:Usuario></sxap:Usuario>
         </sxap:contexto>
         <!--Optional:-->
         <sxap:request>
            <!--Optional:-->
            <sxap:Formulario>
	            <VariableCircuitoConsultaInDTO>
	            <Codigo>From</Codigo>
	            <Valor>20190122</Valor>
	          </VariableCircuitoConsultaInDTO>
	          <VariableCircuitoConsultaInDTO>
	            <Codigo>To</Codigo>
	            <Valor>20190522</Valor>
	          </VariableCircuitoConsultaInDTO>
            </sxap:Formulario>
            <!--Optional:-->
            <sxap:Aditional>
            </sxap:Aditional>
            <!--Optional:-->
            <sxap:Comando>Reporte_5</sxap:Comando>
            <!--Optional:-->
                 <sxap:Paginacion>
               <sxap:NroPagina>0</sxap:NroPagina>
               <sxap:RegistrosPorPagina>20</sxap:RegistrosPorPagina>
               <sxap:RetornaTotalRegistros>false</sxap:RetornaTotalRegistros>
            </sxap:Paginacion>
            <sxap:QuerySettings>
               <apis:Filters>
               </apis:Filters>
               <apis:Paging>
                  <apis:ContinuationToken></apis:ContinuationToken>
                  <apis:PageNumber>1</apis:PageNumber>
                  <apis:PageSize>20</apis:PageSize>
                  <apis:TotalElements>20</apis:TotalElements>
                  <apis:TotalPages>0</apis:TotalPages>
               </apis:Paging>
               <apis:Sorting>
               </apis:Sorting>
            </sxap:QuerySettings>
            <sxap:ReportCode>Reporte_5</sxap:ReportCode>
         </sxap:request>
      </sxap:Invocar>
   </soapenv:Body>
</soapenv:Envelope>

As you can see there are severals differencies. 

Envelop are not the same between Delphi and SOAPUI

Namespace are missing in Delphi generated code.

 

I tried to modify  

 

  InvRegistry.RegisterMethodInfo(TypeInfo(ISrvConsultaCartera), 'Invocar', '','[ReturnName="InvocarResult"]', IS_OPTN or IS_NLBL);

 

to

 

  InvRegistry.RegisterMethodInfo(TypeInfo(ISrvConsultaCartera), 'Invocar', 'sxap:Invocar',[ReturnName="InvocarResult"]', IS_OPTN or IS_NLBL);

This worked but I have no clue on how to do this for other properties (paginacion, paging...)

 

I search the internet but dod not found relevant info. 

Can someone help me on this ?

 

Thank you
 

 

 

Expected Soap Request.xml

ISrvConsultaCartera1.pas

Delphi Generated SOAP Request.xml

Share this post


Link to post

There is also a difference of missing empty soap header in Delphi version

<soapenv:Header/>

You can try creating a soap header and see if it helps.

 

What I do under similar cases is manually creating XML using THTTPRIO.OnBeforeExecute() event.

 

SOAP was using Indy components before. Now it is using THTTPClient in recent versions. Changes presented some bugs like Delphi 10.3.3 version have problem of not reading error message in returned XML if it exists (https://quality.embarcadero.com/browse/RSP-27194). BTW, I do not see any clue about having namespace support for SOAP anywhere.

Share this post


Link to post

What disturbs me the most is the lack of available documentation and examples. 

 

I really don't know how to properly handle this... I've also tried to use Indy and send an pre-formatted XML file (thanks to SOAPUI) but it failed (504 Connection reset by peer). Maybe @Remy Lebeau can helps on this? 

Share this post


Link to post
2 hours ago, Stéphane Wierzbicki said:

I've also tried to use Indy and send an pre-formatted XML file (thanks to SOAPUI) but it failed (504 Connection reset by peer). Maybe @Remy Lebeau can helps on this?

Note without seeing the actual code and a log of the actual TCP communications. Probably the XML was malformed in a way the server didn't like, so it forcibly closed the connection.  Though an HTTP 504 response code is a Gateway Timeout error, it is meant to be used only by gateways, not by servers.  So maybe there is an intermediate proxy between your client and the target server, and the proxy experienced a problem?  Really hard to diagnose something like this without any context or details.

 

Share this post


Link to post
Guest

SOAP - i was forced to implement a link between my software and EWS.

After banging my had against Delpi SOAP, RemoteObjects SOAP (with support) and some other libaries...

I wrote a dll in VS/free exposing my needs in simpler form, the dll i called by my win-service.

Never looked back, SOAP works in VC. No COM as far as you can see!

Share this post


Link to post
On 1/15/2020 at 10:13 PM, Stéphane Wierzbicki said:

What disturbs me the most is the lack of available documentation and examples. 

 

I really don't know how to properly handle this... I've also tried to use Indy and send an pre-formatted XML file (thanks to SOAPUI) but it failed (504 Connection reset by peer). Maybe @Remy Lebeau can helps on this? 

I was more suggesting alternative way to use your web service. Something like semi-manual Delphi SOAP web service use.

 

It is sometimes easier to explain in code. Please check attached demo. Especially file "ISrvConsultaCartera.WS.pas".

 

I could not test everything as your URL was missing in the first place. I do hope that will help you out.

SOAP_before_execute.7z

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×