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

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

Closed
Dialecticus opened this issue Jun 19, 2024 · 6 comments
Closed
Labels

Comments

@Dialecticus
Copy link

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.

Copy link

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

@github-actions github-actions bot added the stale label Jul 20, 2024
@Dialecticus
Copy link
Author

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.

@github-actions github-actions bot removed the stale label Jul 26, 2024
@Dialecticus
Copy link
Author

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
Copy link
Collaborator

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

Copy link

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

@github-actions github-actions bot added the stale label Sep 19, 2024
Copy link

github-actions bot commented Oct 3, 2024

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

@github-actions github-actions bot closed this as completed Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants