简体   繁体   English

soap 1.1的服务堆栈序列化异常

[英]Service Stack Serialization Exception for soap 1.1

The Request Message: 请求消息:

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
  <SendGetAccountNotification xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="mynamespace">
     <getAccountResponse xmlns:d2p1="mynamespace">
        <d2p1:Account>
           <d2p1:BusOpsDesc>String</d2p1:BusOpsDesc>
           <d2p1:ExternalAccountID>String</d2p1:ExternalAccountID>
        </d2p1:Account>
        <d2p1:ExternalAccountID>String</d2p1:ExternalAccountID>
        <d2p1:Message>String</d2p1:Message>
     </getAccountResponse>
  </SendGetAccountNotification>
</soap:Body>
</soap:Envelope>

Response message / error: 响应消息/错误:

<SendGetAccountNotificationResponse xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="mynamespace">
   <ResponseStatus>
      <ErrorCode>SerializationException</ErrorCode>
      <Message>Could not deserialize 'application/xml' request using EServices_Response.SendGetAccountNotification'
Error: System.Runtime.Serialization.SerializationException: Error in line 1 position 170. Expecting element 'SendGetAccountNotification' from namespace 'mynamespace'.. Encountered 'Element'  with name 'Envelope', namespace 'http://schemas.xmlsoap.org/soap/envelope/'. 
   at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
   at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
   at ServiceStack.WebHost.Endpoints.Support.EndpointHandlerBase.DeserializeContentType(Type operationType, IHttpRequest httpReq, String contentType)</Message>
      <StackTrace>at ServiceStack.WebHost.Endpoints.Support.EndpointHandlerBase.DeserializeContentType(Type operationType, IHttpRequest httpReq, String contentType)
   at ServiceStack.WebHost.Endpoints.GenericHandler.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, String operationName)</StackTrace>
   </ResponseStatus>
</SendGetAccountNotificationResponse>

The C# Service: C#服务:

[DataContract(Namespace = "mynamespace")]
public class SendGetAccountResponseService : IService<SendGetAccountNotification>
{
    public object Execute (SendGetAccountNotification request)
    {
        Console.WriteLine ("Reached");
        return null;
    }
}

Question: 题:

Okay so I have been digging around for hours now and I cant find a solution. 好的,所以我已经研究了几个小时,找不到解决方案。 I inserted that request XML into Soap UI and i got that error response. 我将请求XML插入Soap UI,并得到了错误响应。 It looks like it does not like the soap envelope and is trying to serialize the request starting not taking in regard to ignore the Envelope and Serialize the soap body to a model. 看起来好像不喜欢肥皂信封,并且开始尝试序列化请求,开始时并未考虑忽略信封并将肥皂主体序列化为模型。 I have no idea why this is happening, does anyone else know? 我不知道为什么会这样,其他人知道吗? Do i need to add some attributes in somewhere perhaps? 我是否需要在某些地方添加一些属性? Any help will be appreciated. 任何帮助将不胜感激。

Solution: 解:

Look for the green Tick. 寻找绿色的勾号。 Solved this by checking my endpoint, it was pointing to the XML endpoint and therefore i was getting that error message. 通过检查我的端点来解决此问题,它指向XML端点,因此我收到了该错误消息。 I have improved the service by following the post that solved my problem. 通过解决问题的帖子,我改善了服务。 Also noticed that I had an older version of service stack so that is now updated and all works like a charm. 还注意到我有一个较旧的服务堆栈版本,因此现在进行了更新,所有工作都像一个魅力。

Below is my (simplified) attempt at your Service. 以下是我(简化)为您提供服务的尝试。 It ignores 'namespace' but there is more information here . 它忽略“命名空间”,但此处更多信息 I am able to receive a successful response using Soap UI. 我可以使用Soap UI收到成功的响应。

SoapUI setup: SoapUI设置:

Endpoint - http://localhost:1337/soap11 端点 http://localhost:1337/soap11

Request Message: (copied from ServiceStack Metadata page) 请求消息:(从ServiceStack元数据页面复制)

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
<SendGetAccountNotification xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/ServiceStackWinForm">
  <Account>
    <BusOpsDesc>String</BusOpsDesc>
    <ExternalAccountId>12345</ExternalAccountId>
  </Account>
  <ExternalAccountID>String</ExternalAccountID>
  <Message>String</Message>
</SendGetAccountNotification>
    </soap:Body>
</soap:Envelope>

ServiceStack Code: ServiceStack代码:

Account class (part of request): 帐户类别(请求的一部分):

[DataContract]
public class Account
{
    [DataMember]
    public string BusOpsDesc { get; set; }
    [DataMember]
    public string ExternalAccountId { get; set; }
}

Request class 要求等级

[DataContract]
[Route("/SendGetAccountNotification")]
public class SendGetAccountNotification
{
    [DataMember]
    public Account Account { get; set; }
    [DataMember]
    public string ExternalAccountID { get; set; }
    [DataMember]
    public string Message { get; set; }
}

Response class with matching naming convention 具有匹配命名约定的响应类

[DataContract]
public class SendGetAccountNotificationResponse : IHasResponseStatus
{
    [DataMember]
    public String Result { get; set; }
    [DataMember]
    public ResponseStatus ResponseStatus { get; set; }
}

Service 服务

public class SendGetAccountResponseService : Service
{
    public SendGetAccountNotificationResponse Any(SendGetAccountNotification request)
    {
        Console.WriteLine("Reached");
        return new SendGetAccountNotificationResponse() {Result = "Success for Account " + request.Account.ExternalAccountId};
    }
}

I had the same kind of issue, I had to modify the request. 我遇到了同样的问题,我不得不修改请求。 I can't understant why, but I had to remove the prefix. 我不知道为什么,但是我不得不删除前缀。 Try this: 尝试这个:

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
  <SendGetAccountNotification xmlns="http://www.w3.org/2001/XMLSchema-instance" xmlns="mynamespace">
     <getAccountResponse>
        <Account>
           <BusOpsDesc>String</BusOpsDesc>
           <ExternalAccountID>String</ExternalAccountID>
        </Account>
        <ExternalAccountID>String</ExternalAccountID>
        <Message>String</Message>
     </getAccountResponse>
  </SendGetAccountNotification>
</soap:Body>
</soap:Envelope>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM