DigDes / SoapCore

SOAP extension for ASP.NET Core
MIT License
1k stars 378 forks source link

Double definition in WSDL when collection of enums is named with XmlElement #1070

Closed Dialecticus closed 1 month ago

Dialecticus commented 4 months ago

If a collection of enums has a bare XmlElement attribute attached then WSDL is correct, but if the name is added to the attribute then weird double definition appears in WSDL. Take this code:

using SoapCore;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.Xml.Serialization;

internal class Program
{
    private static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);

        builder.Services.AddControllers().AddXmlSerializerFormatters();
        builder.Services.AddSoapCore();
        builder.Services.AddScoped<ITesting, Testing>();

        var app = builder.Build();

        app.UseHttpsRedirection();
        app.UseRouting();
        app.UseAuthorization();
        app.UseEndpoints(endpoints => { endpoints.UseSoapEndpoint<ITesting>("/Testing", new SoapEncoderOptions(), SoapSerializer.XmlSerializer); });
        app.MapControllers();
        app.Run();
    }
}
public class Testing : ITesting
{
    private IWebHostEnvironment Environment;

    public Testing(IWebHostEnvironment _environment)
    {
        Environment = _environment;
    }

    public void Test(ExampleClass someObj)
    {
        throw new NotImplementedException();
    }

}

[ServiceContract(Namespace = "http://example.org/")]
public interface ITesting
{
    [OperationContract]
    public void Test(ExampleClass someObj);
}

public enum ExampleEnum
{
    One,
    Two,
}

[Serializable]
public class ExampleClass
{
    [XmlElement("ExampleProp")]
    //[XmlElement] // No errors if stated without the name
    public Collection<ExampleEnum> ExampleProp { get; set; }
}

Resulting WSDL will have this:

  <xsd:complexType name="ExampleEnum">
    <xsd:sequence>
      <xsd:element minOccurs="1" maxOccurs="1" name="value__" type="xsd:int" />
      <xsd:element minOccurs="1" maxOccurs="1" name="One" type="tns:ExampleEnum" />
      <xsd:element minOccurs="1" maxOccurs="1" name="Two" type="tns:ExampleEnum" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:simpleType name="ExampleEnum">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="One" />
      <xsd:enumeration value="Two" />
    </xsd:restriction>
  </xsd:simpleType>

This simpleType is expected, but this complexType is an error. The error will not show if XmlElement attribute does not have the ElementName set.

github-actions[bot] commented 3 months ago

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

Dialecticus commented 3 months ago

No response after five weeks. Would just like to know if I am doing something wrong, or there is a bug in SoapCore, both for this issue and for #1069.

Dialecticus commented 2 months ago

No wonder there are only a few open issues for this project. They get automatically closed after two months. Lack of response is concerning. To say "won't do, don't have time right now" would be at least understandable. One star.

andersjonsson commented 2 months ago

I seem to be the only somewhat active maintainer here and I don't have a lot of time to dedicate to this project.

You seem to have encountered a bug. A PR would be appreciated if you can find the time. There are examples in the test suite that uses the elementname property of XmlElement, but those are probably not validating the wsdl

github-actions[bot] commented 1 month ago

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

github-actions[bot] commented 1 month ago

This issue was closed because it has been inactive for 14 days since being marked as stale.