【问题标题】:Defining ASP.NET SOAP web service response定义 ASP.NET SOAP Web 服务响应
【发布时间】:2012-05-28 22:07:59
【问题描述】:

抱歉,如果这是一个业余问题。我必须修改现有的 ASMX Web 服务。问题是,我需要修改 Web 服务生成的响应。以下是当前响应的示例:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" mlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <InsertCaseShortResponse xmlns="http://website.com/Service/">
      <InsertCaseShortResult>50314</InsertCaseShortResult>
    </InsertCaseShortResponse>
  </soap:Body>
</soap:Envelope>

InsertCaseShortResult 如果成功则返回唯一的参考号,如果失败则返回错误消息。我需要做的是添加另一个响应标签,它给出了一个关于插入是否成功的真或假标志。我无法在任何地方找到有关如何构建 Web 服务响应的大量信息,我认为我在这里缺少一个基本元素。

非常感谢任何想法。

【问题讨论】:

  • 如果您有 WSDL,这是一个很好的起点。之后,必须知道如何部署 Web 服务,在这种情况下,遗留的意义就很小了。

标签: asp.net web-services soap asmx


【解决方案1】:

我假设您所说的“遗留”是指 ASMX Web 服务。

根据您的 WSDL,您的 Web 服务服务器端代码中似乎有这样的内容:

[WebMethod]
public int InsertCaseShort(/* params here */)
{
    int result;

    /* Code here */

    return result;
}

要添加附加字段,您需要返回类引用而不是整数值。

示例:

public class InsertCaseShortResult
{
    public int StatusCode { get; set; }
    public bool Successful { get; set; }
}

在你的 WebMethod 中:

[WebMethod]
public InsertCaseShortResult InsertCaseShort(/* params here */)
{
    var result = new InsertCaseShortResult();

    /* Code here */

    return result;
}

如有任何其他问题,请随时提出。

【讨论】:

  • 啊,我明白了。那么响应的格式取决于 web 方法的返回类型?非常感谢,这非常有帮助:)
  • 是的,我指的是 ASMX Web 服务。我编辑了我的原始问题以向其他人澄清
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-29
相关资源
最近更新 更多