DigDes / SoapCore

SOAP extension for ASP.NET Core
MIT License
988 stars 371 forks source link

SoapCore not deserializing the soap request correctly #1077

Open swastiks opened 1 month ago

swastiks commented 1 month ago

We have a legacy soap envelop like below which references a product xml using href as shown below.

``` 123456 Noodles Food ``` We have a service contract like below. We want to be able to deserialize above soaprequest into following webmethod. ``` [ServiceContract(Namespace = "http://webservices.google.net/abc.NET")] public interface IProductTallier { [OperationContract(Name = "Tally_Test")] Task Tally(string SerialNumber, Product product); } ``` Currently, we are facing two problems with soap core. 1. We are getting following soap error because soapcore is expecting Tally_Test envelop to be sent instead of Tally when calling SoapAction Tally_Test. How do we resolve this? > > s:Client > Start element 'Tally_Test' from namespace 'http://webservices.google.net/abc.NET' expected. Found element 'tns:Tally' from namespace 'http://webservices.google.net/abc.NET'. > 2. If we modify the above soap envelop with Tally_Test instead of Tally, the webmethod is getting called without any soap fault. However, the product is not deserialized correctly and its empty. Is there any way we can deserialize above soap envelop correctly?
ankitkmrpatel commented 1 month ago

Hi @swastiks,

We encountered a similar issue with our legacy service. After some investigation, we discovered that the problem was related to using a custom serializer to our SOAP service. We figured this out Attribute applied in our service and resolve using the ReplaceDataContractSerializerOperationBehavior method, as shown below:

[OperationContract]
[MessageOperationFormat]
[FaultContract(typeof(ApplicationFault), Action = "http://ourproductenterprise.com/productname/2010/06/FaultAction")]

Where MessageOperationFormat has the following implementations:

public class MessageOperationFormatAttribute : Attribute, IOperationBehavior
{
    private void ReplaceDataContractSerializerOperationBehavior(OperationDescription operationDescription)
    {
        DataContractSerializerOperationBehavior dataContractSerializerOperationBehavior = operationDescription.Behaviors.Find<DataContractSerializerOperationBehavior>();
        if (dataContractSerializerOperationBehavior != null)
        {
            int index = operationDescription.Behaviors.IndexOf(dataContractSerializerOperationBehavior);
            operationDescription.Behaviors.Remove(dataContractSerializerOperationBehavior);
            operationDescription.Behaviors.Insert(index, new MessageSerializerOperationBehavior(operationDescription));
        }
    }
}

You might want to check if your legacy service has a similar workaround. We resolved our issue by implementing a custom serializer using SoapCore.

Alternatively, you can modify the interface or write a custom serializer using the options provided in SoapCore. However, you might need to wait for a new release or fork the repository to generate the package yourself.

Hope this helps!

github-actions[bot] commented 1 week ago

This issue is stale because it has been open for 30 days with no activity.