Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to consume a WCF service with CustomBinding endpoint with messageversion as Soap12 #2711

Closed
ranjitkrishnan opened this issue Mar 23, 2018 · 11 comments
Assignees
Labels
bug This is a product bug.

Comments

@ranjitkrishnan
Copy link

ranjitkrishnan commented Mar 23, 2018

I have to consumer a WCF service from my Core2.0 API. The WCF service has custombiding with messageVersion as Soap12.

Please find the wcf service binding configuration.

<customBinding>
        <binding closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00">
          <textMessageEncoding  messageVersion ="Soap12">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          </textMessageEncoding>
          <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" useDefaultWebProxy="true" transferMode="Buffered" />
        </binding>
      </customBinding>

I am using System.ServiceModel.Primitives to create the CustomBinding from my .NET Core Code.

Please find the code below

           
            var binding = new CustomBinding();
TextMessageEncodingBindingElement textBindingElement = new TextMessageEncodingBindingElement
            {
                MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None),
                WriteEncoding = System.Text.Encoding.UTF8,
                ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max
            };

            binding.Elements.Add(textBindingElement);

            HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement
            {
                AllowCookies = false,
                MaxBufferSize = int.MaxValue,
                MaxReceivedMessageSize = int.MaxValue,
                TransferMode= TransferMode.Buffered
            };
            binding.Elements.Add(httpBindingElement);

I am getting the below error from this call.

ActionNotSupportedException: The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None)

This will work for any other message version like Soap11, Soap12WSAddressing10 which is directly present in MessageVersion class. It is not working when i am creating messageversion using CreateVersion method as there is no in-built support for Soap12 as it used to be with the framewrok dll

@ranjitkrishnan ranjitkrishnan changed the title Not able to consume a service with CustomBinding endpoint with textMessageEncoding with messageversion as Soap12 Not able to consume a WCF service with CustomBinding endpoint with messageversion as Soap12 Mar 23, 2018
@Lxiamail Lxiamail added this to the S133 milestone Mar 29, 2018
@Looooooka
Copy link

Looooooka commented Apr 4, 2018

I have the same problem(also consuming from net core 2. Soap11 works Soap12 throws this exception. In fact I can't even see the request going out in fiddler
The difference is I am using HttpsTransportBindingElement.

@rajput81
Copy link

Hi, My .net solution was implemented to use custom binding on Soap11WSAddressing10, when moving to .Net core Soap11WSAddressing10 was not available option and Soap12WSAddressing10 is not working :(
Can we have Soap11WSAddressing10 available in .Net core please?

@Lxiamail Lxiamail modified the milestones: S133, S134 Apr 20, 2018
@mconnew
Copy link
Member

mconnew commented Apr 23, 2018

I did some investigation and I can understand why Soap11WSAddressing10 doesn't work. The code for Soap11 here is missing on core. The issue with just Soap12 I'm not able to see what the issue is after a few minutes of digging through the code and I'll need to do more investigation.

@Lxiamail Lxiamail added the bug This is a product bug. label May 11, 2018
@Lxiamail
Copy link
Member

@mconnew Need open test issue for write tests for Soap11WSAddressing10 and Soap12, include details needed.

@Lxiamail Lxiamail modified the milestones: S134, 2.2.0 May 11, 2018
@Lxiamail Lxiamail modified the milestones: 3.0, 2.1.0 May 25, 2018
@Lxiamail Lxiamail modified the milestones: 3.0, S136 May 25, 2018
@Lxiamail Lxiamail modified the milestones: S136, S138, S139 Jun 29, 2018
@Lxiamail
Copy link
Member

Lxiamail commented Aug 3, 2018

@StephenBonikowsky Can we have test for this?

@StephenBonikowsky
Copy link
Member

I have added tests that reproduce the error, #3132
I have updated the issue that had been opened to track adding the tests with the details, #2864

@swiftarrow101
Copy link

Hello,
I am seeing the same issue in .Net Core 2.0
Has this been fixed in 2.1?
Thanks

@Lxiamail
Copy link
Member

@swiftarrow101 This hasn't been fixed yet, however, it is in our pipe to work on.

@gekiss
Copy link

gekiss commented Nov 1, 2018

Soap12 without Addressing lost the action attribute in the ContentType header.

The quicker solution is move lines from

if (message.Version.Addressing == AddressingVersion.None)
{
message.Headers.Action = null;
message.Headers.To = null;
}

to

@Lxiamail Lxiamail modified the milestones: S140, 3.0 Nov 7, 2018
@bdrupieski
Copy link

Is there a workaround for this issue until it's fixed in a future release?

@bdrupieski
Copy link

bdrupieski commented Jan 20, 2019

I think I came up with a workaround. After looking through the source I saw that if I try to add a "SOAPAction" header, it will be added as a Content-Type header parameter.

This seems to work:

private static T AddSoapActionHeader<T>(Expression<Func<T>> expression)
{
    var method = ((MethodCallExpression)expression.Body).Method;
    var operationContract = method.DeclaringType.GetInterfaces()
        .Select(interfaceType => interfaceType.GetMethods())
        .SelectMany(interfaceMethods => interfaceMethods)
        .Where(interfaceMethod => interfaceMethod.Name == method.Name)
        .Select(interfaceMethod => interfaceMethod.GetCustomAttribute<OperationContractAttribute>())
        .FirstOrDefault(attr => attr != null);

    using (new OperationContextScope(_client.InnerChannel))
    {
        if (!string.IsNullOrEmpty(operationContract?.Action))
        {
            OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = new HttpRequestMessageProperty
            {
                Headers =
                {
                    { "SOAPAction", $"\"{operationContract.Action}\"" },
                }
            };
        }

        var func = expression.Compile();
        return func();
    }
}

I have to wrap every method call with it, so this:

var products = _client.getProductList(id);

becomes:

var products = AddSoapActionHeader(() => _client.getProductList(id));

edit:
Alternatively, you can use it like this if it's an extension method:

var products = _client.AddSoapActionHeader(() => _client.getProductList(id));
public static class ClientBaseExtensions
{
    public static T AddSoapActionHeader<TClientInterface, T>(this ClientBase<TClientInterface> client, Expression<Func<T>> expression) 
        where TClientInterface : class
    {
        var method = ((MethodCallExpression)expression.Body).Method;
        var operationContract = method.DeclaringType.GetInterfaces()
            .Select(interfaceType => interfaceType.GetMethods())
            .SelectMany(interfaceMethods => interfaceMethods)
            .Where(interfaceMethod => interfaceMethod.Name == method.Name)
            .Select(interfaceMethod => interfaceMethod.GetCustomAttribute<OperationContractAttribute>())
            .FirstOrDefault(attr => attr != null);

        using (new OperationContextScope(client.InnerChannel))
        {
            if (!string.IsNullOrEmpty(operationContract?.Action))
            {
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = new HttpRequestMessageProperty
                {
                    Headers =
                    {
                        { "SOAPAction", $"\"{operationContract.Action}\"" },
                    }
                };
            }

            var func = expression.Compile();
            return func();
        }
    }
}

@Lxiamail Lxiamail modified the milestones: 3.0, S149 Feb 28, 2019
CameronS29 pushed a commit to CameronS29/Soap-.NET-Core that referenced this issue May 9, 2020
Updated namespace for SOAP 1.2 to fix #181 

I had to wrote it this way, because .NET Core currently doesn't have 'Soap12' MessageVersion member. When it will be present (see dotnet/wcf#2711) implementation should be updated to cover new member.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a product bug.
Projects
None yet
Development

No branches or pull requests

9 participants