简体   繁体   English

ASMX 服务错误 - 使用 XmlInclude 或 SoapInclude 属性指定静态未知的类型

[英]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.

相关问题 使用 XmlInclude 或 SoapInclude 属性指定静态未知的类型 - Use the XmlInclude or SoapInclude attribute to specify types that are not known statically “不希望使用RoleProxy类型。 使用XmlInclude或SoapInclude属性可以指定静态未知的类型。” NHibernate - “The type RoleProxy was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.” NHibernate xxx类型不是预期的。 使用XmlInclude或SoapInclude属性来指定静态未知的类型 - The type xxx was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically 调用Web服务时出现问题-使用XmlInclude或SoapInclude属性 - Issue calling a web service - Use the XmlInclude or SoapInclude attribute 如何使用XmlInclude动态指定类型? - How to use XmlInclude to specify types dynamically? 类型xxxx不期望使用xmlinclude或soapinclude - type xxxx not expected use xmlinclude or soapinclude Xml序列化异常:不需要类型UserQuery + SpecificContentItem。 使用XmlInclude或SoapInclude - Xml serialization Exception : The type UserQuery+SpecificContentItem was not expected. Use the XmlInclude or SoapInclude WCF服务引发“未预期类型[…]。 即使已经使用XmlInclude,也要使用XmlInclude […]” - WCF service throws “The type […] was not expected. Use the XmlInclude […]” even if XmlInclude is already being used 这个错误是什么意思? 考虑使用DataContractResolver或添加任何静态未知的类型 - What does this error mean? Consider using a DataContractResolver or add any types not known statically DataContractJsonSerializer序列化错误:考虑使用DataContractResolver或将静态未知的任何类型添加到列表中 - DataContractJsonSerializer serialization error: Consider using a DataContractResolver or add any types not known statically to the list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM