SoapCore
SoapCore copied to clipboard
received method argument null
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
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.
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
Ok, then you need to read the stream in some other way, like a streamreader
okay, it works with StreamReader
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.