【发布时间】:2023-01-20 00:14:50
【问题描述】:
使用 SoapCore 将 POST 从 Postman 发送到 VS .NET Core 7 时,命中服务方法的值为 NULL。我认为我对 SOAP 请求的格式设置错误?感谢所有帮助过的人!
我的自定义模型.cs
[DataContract]
public class MyCustomModel
{
[DataMember]
public int Id { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Email { get; set; }
}
示例服务.cs
public class SampleService : ISampleService
{
public string Test(string s) // This works
{
Console.WriteLine("Test Method Executed!");
return s;
}
public void XmlMethod(XElement xml) // customModel NULL here
{
Console.WriteLine(xml.ToString());
}
public MyCustomModel TestCustomModel([FromBody] MyCustomModel customModel) // customModel NULL here
{
return customModel;
}
}
启动文件
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.TryAddSingleton<ISampleService, SampleService>();
services.AddSoapCore();
services.AddMvc();
}
public void Configure(IApplicationBuilder app)
{
app.UseSoapEndpoint<ISampleService>("/Service.asmx", new SoapEncoderOptions(), SoapSerializer.XmlSerializer);
}
}
WSDL
【问题讨论】:
标签: soap