[英]ASMX Service Error - Use the XmlInclude or SoapInclude attribute to specify types that are not known statically
I have an Asmx service with a web method.我有一个带有 web 方法的 Asmx 服务。 Within that web method i am calling a rest endpoint (Logic app endpoint).
在该 web 方法中,我正在调用 rest 端点(逻辑应用程序端点)。 The logic app rest endpoint accepts the request and returns a success 200 response.
逻辑应用 rest 端点接受请求并返回成功 200 响应。
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("base address");
var content = new StringContent(JsonConvert.SerializeObject(request, Formatting.Indented), Encoding.UTF8, "application/json");
var result = await client.PostAsync("some-uri", content);
}
As soon as i hit the client.postasync line i get the following error:一旦我点击 client.postasync 行,我就会收到以下错误:
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.Threading.Tasks.Task`1[[System.Threading.Tasks.VoidTaskResult, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write2_Task(String n, String ns, Task o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write3_Task(Object o)
at Microsoft.Xml.Serialization.GeneratedAssembly.TaskSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
I found the error.我发现了错误。 The webmethod was made async and that caused this issue.
webmethod 是异步的,这导致了这个问题。 I made the web method to return void and changed the http client post request line of code to the following:
我使 web 方法返回 void 并将 http 客户端发布请求代码行更改为以下代码:
var result = client.PostAsync(reqUri, requestContent).GetAwaiter().GetResult();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.