1

请求消息:

<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>

响应消息/错误:

<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>

C# 服务:

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

问题:

好的,所以我已经挖掘了几个小时,但我找不到解决方案。我将该请求 XML 插入到 Soap UI 中,我得到了错误响应。看起来它不喜欢肥皂信封,并试图序列化请求,开始不考虑忽略信封并将肥皂体序列化为模型。我不知道为什么会这样,有其他人知道吗?我是否需要在某处添加一些属性?任何帮助将不胜感激。

解决方案:

寻找绿色的勾号。通过检查我的端点解决了这个问题,它指向 XML 端点,因此我收到了该错误消息。我按照解决我的问题的帖子改进了服务。还注意到我有一个旧版本的服务堆栈,所以现在已经更新,所有的工作都像一个魅力。

4

2 回答 2

2

以下是我对您的服务的(简化)尝试。它忽略了“命名空间”,但这里有更多信息。我能够使用 Soap UI 收到成功的响应。

SoapUI 设置:

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

请求消息:(从 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>

服务栈代码:

帐户类(请求的一部分):

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

请求类

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

具有匹配命名约定的响应类

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

服务

public class SendGetAccountResponseService : Service
{
    public SendGetAccountNotificationResponse Any(SendGetAccountNotification request)
    {
        Console.WriteLine("Reached");
        return new SendGetAccountNotificationResponse() {Result = "Success for Account " + request.Account.ExternalAccountId};
    }
}
于 2013-05-14T15:08:51.660 回答
0

我有同样的问题,我不得不修改请求。我不明白为什么,但我不得不删除前缀。尝试这个:

<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>
于 2013-05-14T14:37:40.293 回答