SoapCore icon indicating copy to clipboard operation
SoapCore copied to clipboard

received method argument null

Open Webroker opened this issue 1 year ago • 4 comments

I implemented in VS .NET8 your project as indicated

public class Program { public static void Main(string[] args) { CreateHostBuilder(args).Build().Run(); } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }); }

public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddSoapCore(); services.TryAddSingleton<Hl7MessagePortService>(); services.AddControllers(); }

public void Configure(IApplicationBuilder app)
{
    app.UseRouting();

    app.UseEndpoints(endpoints =>
    {
        endpoints.UseSoapEndpoint<Hl7MessagePortService>("/Service.asmx", new SoapEncoderOptions(), SoapSerializer.XmlSerializer);
        endpoints.MapControllers();
    });
}

}

and I added this service public class Hl7MessagePortService : IHl7MessagePort { public GetEnqueueResponse GetEnqueue(GetEnqueueRequest request) { GetEnqueueResponse response = new GetEnqueueResponse(); return response; } }

with this interface namespace Exprivia.WebServices.Queue { [ServiceContract(Namespace = "http://www.exprivia.com/webservices/queue")] public interface IHl7MessagePort { [OperationContract] GetEnqueueResponse GetEnqueue(GetEnqueueRequest request); }

[MessageContract]
public class GetEnqueueRequest
{
    [MessageBodyMember]
    public string QueueName { get; set; }

    [MessageBodyMember]
    public string Message { get; set; }
}

[MessageContract]
public class GetEnqueueResponse
{
    [MessageBodyMember]
    public Response Response { get; set; }

    [MessageBodyMember]
    public string Message { get; set; }
}

public enum Response
{
    OK,
    KO
}

public class Entry
{
    public string Key { get; set; }
    public string Value { get; set; }
}

public class HeadersMap
{
    public List<Entry> Entries { get; set; }
}

public class ContextMap
{
    public List<Entry> Entries { get; set; }
}

} when the server receive the call GetEnqueue the method argument is always null what can I do to solve this problem, thanks

Webroker avatar Jan 26 '24 11:01 Webroker

What does the incoming xml look like?

You can add a middleware, like this:

app.Use(async (context, next) =>
{
	if (context.Request.Method == "POST")
	{
		//This line allows us to set the reader for the request back at the beginning of its stream.
		context.Request.EnableBuffering();

		//We convert the byte[] into a string using UTF8 encoding...
		var bodyAsText = Encoding.UTF8.GetString(await context.Request.Body.ReadFullyAsync());

		try
		{
			var xdoc = XDocument.Parse(bodyAsText);

			bodyAsText = xdoc.ToString();
			context.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsText));

		}
		catch
		{ }

		//..and finally, assign the read body back to the request body, which is allowed because of EnableRewind()
		context.Request.Body.Position = 0;
	}

	await next();
}

);

to check the incoming payload.

andersjonsson avatar Feb 05 '24 12:02 andersjonsson

the code var bodyAsText = Encoding.UTF8.GetString(await context.Request.Body.ReadFullyAsync()); return error 'Stream' does not contain a definition of 'ReadFullyAsync' and no accessible 'ReadFullyAsync' extension method was found that takes a first argument of type 'Stream'. You're probably missing a using directive or assembly reference. SOAPService

Webroker avatar Feb 06 '24 17:02 Webroker

Ok, then you need to read the stream in some other way, like a streamreader

andersjonsson avatar Feb 06 '24 18:02 andersjonsson

okay, it works with StreamReader

Webroker avatar Feb 18 '24 18:02 Webroker

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

github-actions[bot] avatar Mar 20 '24 02:03 github-actions[bot]

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

github-actions[bot] avatar Apr 03 '24 02:04 github-actions[bot]