Search code examples
c#.netsoapservicestack

Creating a soap endpoint from WSDL in .net


I am trying to create a SOAP web service that will be consumed by another company. This company expects to give the data in a certain way, hence I have created a WSDL to reflect that. I don't need to auto-generate the service from the WSDL, but if I could that would be nice. I am just trying to create a service that will consume data, like the WSDL suggests. I am using .net core 6.

I have tried using serviceStack And I built out the envelope/header/body classes, such that it performs as desired. But it seems a little wonky because I am unable to query the WSDL.

If my service is pointing to https://myurl/web_services/doStuff,

I should be able to query https://myurl/web_services/doStuff?WSDL to get the WSDL

I am open to restarting the project if ServiceStack is no good, but it seems like hosting a WSDL should be kind of automatic.

Here is my service code:

public class MyServices : Service
{
    public object Any(Envelope request)
    {
        return new EnvelopeResponse(request);
    }

    // should I have to have this method to get the WSDL?
    public object Get(WSDL request)
    {
        return new WSDLResponse();
    }
}

Here is my envelope class:

[Route("/web_services/doStuff", "POST")]
[DataContract]
public class Envelope : IReturn<EnvelopeResponse>
{
    [DataMember(Name = "Header", Order = 0)]
    public Header Header { get; set; }

    [DataMember(Order = 1)]
    public Body Body { get; set; }
}

When I try to manually return the WSDL it serializes the WSDL class into XML, so I would need to manually build a WSDL class, which doesn't feel right.

[Route("/web_services/doStuff", "GET")]
[DataContract]
public class WSDL : IReturn<WSDLResponse> {}

[DataContract]
public class WSDLResponse 
{
  
    public WSDLResponse()
    {
        // return wsdl file contents here?
        Result = "wsdL";
    }
    
    [DataMember]
    public string Result { get; set; }
}

Program.cs

var builder = WebApplication.CreateBuilder(args);


var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
    app.UseHttpsRedirection();
}
app.UseServiceStack(new AppHost());

app.Run();

I've looked over all the relevant ServiceStack documentation and I can not find anything helpful about WSDL

I am either trying to create a new service from this WSDL, or host a WSDL from the same URL


Solution

  • This is almost certainly not how you are supposed to do it, but I managed to get the WSDL to display on get method.

    I updated my service to import my handmade WSDL, then I added a header to return the WSDL as XML

    
    public class MyServices : Service
    {
        public object Any(Envelope request)
        {
            return new EnvelopeResponse(request);
        }
    
        [AddHeader(ContentType = MimeTypes.Xml)]
        public object Get(WSDL request)
        {
            return System.IO.File.ReadAllText("myServiceName.wsdl");
        }
    }