From Consuming SOAP service in SoapUI to consuming it with CSHARP

Claudia Murialdo 1 Reputation point
2022-10-15T14:00:40.893+00:00

Hello, I have a project in SOAP UI that consumes a soap service and works well. The service has ws-security and addressing.
I'm trying to do the same, programmatically with csharp and WCF. I have tried many configurations at app.config but it keeps failing. It would be helpful if you can provide me with a guide for the correspondence between soap ui and WCF configuration.

Here is the soap ui project:

250778-iniciosolicitud-soapui-projecttest.xml
And here is the configuration I'm trying at app.config for my c# console application that consumes the same service.
250792-atestiniciosolicitudmainexeconfig.xml

And this is the method BeforeSendRequest of my custom binding to configure Adressing which seems to work well.

public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
{
if (gxLocation != null && gxLocation.WSAddressing != null)
{
if (gxLocation.WSAddressing.Action != null)
request.Headers.Action = gxLocation.WSAddressing.Action;
if (gxLocation.WSAddressing.FaultTo != null)
request.Headers.FaultTo = GxHelpers.BuildEndpointAddress(gxLocation.WSAddressing.FaultTo);
if (gxLocation.WSAddressing.From != null)
request.Headers.From = GxHelpers.BuildEndpointAddress(gxLocation.WSAddressing.From);
if (!string.IsNullOrEmpty(gxLocation.WSAddressing.MessageID))
request.Headers.MessageId = new UniqueId(gxLocation.WSAddressing.MessageID);
if (!string.IsNullOrEmpty(gxLocation.WSAddressing.RelatesTo))
request.Headers.RelatesTo = new UniqueId(gxLocation.WSAddressing.RelatesTo);
if (gxLocation.WSAddressing.ReplyTo != null)
request.Headers.ReplyTo = GxHelpers.BuildEndpointAddress(gxLocation.WSAddressing.ReplyTo);
if (!string.IsNullOrEmpty(gxLocation.WSAddressing.To))
request.Headers.To = new Uri(gxLocation.WSAddressing.To);

        }  
        Guid guid = Guid.NewGuid();  
        return guid;  
    }  
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,574 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,580 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,136 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    1 deleted comment

    Comments have been turned off. Learn more

  2. Claudia Murialdo 1 Reputation point
    2022-10-18T18:13:16.17+00:00

    Update:
    I got the right configuration with the following custom bindings.
    The only problem is that the body does not get encrypted as expected, given the messageProtectionOrder="EncryptBeforeSign". It seems to be a bug of WCF.

    <customBinding >
    <binding name="gxWsSoapBinding">
    <textMessageEncoding messageVersion="Soap12WSAddressing10" writeEncoding="utf-8" />
    <security authenticationMode="MutualCertificate"
    defaultAlgorithmSuite="Basic128"
    messageProtectionOrder="EncryptBeforeSign"
    securityHeaderLayout="Lax"
    includeTimestamp="false"
    messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
    </security>
    <httpsTransport />
    </binding>
    </customBinding>

    .......

    <endpointBehaviors>
    <behavior name="gxCustomBehaviorConfig">
    <clientCredentials>
    <!--Specify a certificate to use for authenticating the client SIGNATURE.-->
    <clientCertificate findValue="privatekey.client" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My" >
    </clientCertificate>
    <!--Cert used for encryption-->
    <serviceCertificate >
    <defaultCertificate storeLocation="LocalMachine" storeName="My" findValue="publickey.service.com" x509FindType="FindBySubjectName" />
    <authentication certificateValidationMode="None" revocationMode="NoCheck"/>
    </serviceCertificate>
    </clientCredentials>
    </behavior>
    </endpointBehaviors>