106
Views
10
Comments
Solved
how to change/add prefix to soap request

Hi,

OutSystems generate wrong soap request, as below

the expected request XML :

<soapenv:Envelope xmlns:agw="https://*****/agw" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

  <soapenv:Header/>

  <soapenv:Body>


out system generate :

<s:Envelope xmlns:a="https://*****/agw" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">

  <s:Header/>

  <s:Body>


how could we change this behavior? 



2020-11-10 12-18-31
Abdullah Alzahrani
Solution

I found the issue and solved it :)

The solution basically. I need to create  custom extension to sign The request.

so I take the code in this article and use it as a base for my extension. 


this is the code I did to solve this issue :)


public void MssSetupCertificateAuth(byte[] ssServerCertificateContent, byte[] ssClientCertificateContent, string ssCertificatePassword)

        {

            ISOAPClient client = SoapRequest.GetCurrentClient();

            

            var clientCert = new X509Certificate2(ssClientCertificateContent, ssCertificatePassword);

            var serverCert = new X509Certificate2(ssServerCertificateContent);


            //X509Certificate2 serverCert = GetCertificateFromStore("ef23d67f06681fde8d67cc7c485293de636e3311");


            // configure binding to accept certificates

            client.Endpoint.Binding = GetCustomBinding();

           

            client.ClientCredentials.ClientCertificate.Certificate = clientCert;

            client.ClientCredentials.ServiceCertificate.DefaultCertificate = serverCert;

            client.Endpoint.Contract.ProtectionLevel = System.Net.Security.ProtectionLevel.Sign;



        }


 private System.ServiceModel.Channels.Binding GetCustomBinding()

        {


            var transpor = new HttpsTransportBindingElement();

                transpor.RequireClientCertificate = true;

 

            var textMessageEncoding = new TextMessageEncodingBindingElement();

            TextMessageEncoding.MessageVersion = MessageVersion.Soap11;



            var version = MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;

            var security =  SecurityBindingElement.CreateMutualCertificateBindingElement(version, true);


            return new CustomBinding(security, textMessageEncoding, transpor);


        }

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Great to see you have it fixed! I recently created an extension like that as well (with much more added), so I can feel your pain :D.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Not sure why you consider this wrong. It has the right xmlns attributes, it just differs in the namespace, but that shouldn't be a problem.

2020-11-10 12-18-31
Abdullah Alzahrani

I am consuming an external service and it returns an error because of that


also the server expect me to send the body like this:


expected:

 <soapenv:Body>

    <agw:AcctsMngAGWRq>

      <agw:MsgRqHdr>

        <agw:RqUID>14d3dfe8-e72e-4089-9d59-10d24419451d</agw:RqUID>

      </agw:MsgRqHdr>

      <agw:Body>

        <agw:BatchId>201907233001</agw:BatchId>

      </agw:Body>

    </agw:AcctsMngAGWRq>

  </soapenv:Body>

out system generate:

  <s:Body>

  <AcctsMngAGWRq>

    <MsgRqHdr>

      <RqUID>14d3dfe8-e72e-4089-9d59-10d24419451d</RqUID>

    <MsgRqHdr>

    <Body>

      <BatchId>201907233001</agw:BatchId>

    </Body>

  </AcctsMngAGWRq>

</s:Body>

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Can you show what error the server gives?

I'm not sure about the lacking namespace of the other tags, whether that could or should give errors.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

This topic could also be of use. It describes adding a namespace.

2020-11-10 12-18-31
Abdullah Alzahrani

this is the error
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<s:Header xmlns:s="http://www.w3.org/2003/05/soap-envelope" />
<env:Body>
<env:Fault>
<env:Code>
<env:Value>
env:Receiver</env:Value>
</env:Code>
<env:Reason>
<env:Text xml:lang="en-US">
Internal Error (from server)
</env:Text>
</env:Reason>
</env:Fault>
</env:Body>
</env:Envelope>

also, i tried the XML generated by OutSystems on SOAP UI and return the same error but after changing it to the expected one the request's success :)


The post you mention works if we expose the services but In my case, i am the consumer :)

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Given that the reply also uses "s" as namespace, I think then that the lacking namespace on the return is the problem. I don't know how to solve that though. Probably you need some OnBeforeRequestAdvanced and fix it in an Extension.

2020-11-10 12-18-31
Abdullah Alzahrani

I found out outsystem generate the request as soap version 1.2 when the server expect us to send 1.1

note outsystems didn't ask me which version should I use and I don't see any option to do that.

is there any way to do that without writing a custom extension

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

I don't think so. This article states:

"The SOAP implementation available in previous versions, supporting up to SOAP 1.1, is now deprecated. This implementation is only used in modules upgraded to OutSystems 11; any new consumed SOAP web services in OutSystems 11 use the new implementation."

On the other hand, one could also read it to mean that "the new implementation" supports SOAP 1.1 and 1.2, but I'm not sure how consuming a web service should detect which version to send.

2020-11-10 12-18-31
Abdullah Alzahrani
Solution

I found the issue and solved it :)

The solution basically. I need to create  custom extension to sign The request.

so I take the code in this article and use it as a base for my extension. 


this is the code I did to solve this issue :)


public void MssSetupCertificateAuth(byte[] ssServerCertificateContent, byte[] ssClientCertificateContent, string ssCertificatePassword)

        {

            ISOAPClient client = SoapRequest.GetCurrentClient();

            

            var clientCert = new X509Certificate2(ssClientCertificateContent, ssCertificatePassword);

            var serverCert = new X509Certificate2(ssServerCertificateContent);


            //X509Certificate2 serverCert = GetCertificateFromStore("ef23d67f06681fde8d67cc7c485293de636e3311");


            // configure binding to accept certificates

            client.Endpoint.Binding = GetCustomBinding();

           

            client.ClientCredentials.ClientCertificate.Certificate = clientCert;

            client.ClientCredentials.ServiceCertificate.DefaultCertificate = serverCert;

            client.Endpoint.Contract.ProtectionLevel = System.Net.Security.ProtectionLevel.Sign;



        }


 private System.ServiceModel.Channels.Binding GetCustomBinding()

        {


            var transpor = new HttpsTransportBindingElement();

                transpor.RequireClientCertificate = true;

 

            var textMessageEncoding = new TextMessageEncodingBindingElement();

            TextMessageEncoding.MessageVersion = MessageVersion.Soap11;



            var version = MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;

            var security =  SecurityBindingElement.CreateMutualCertificateBindingElement(version, true);


            return new CustomBinding(security, textMessageEncoding, transpor);


        }

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Great to see you have it fixed! I recently created an extension like that as well (with much more added), so I can feel your pain :D.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.