web-services - Web 服务调用具有 "out"参数是否不寻常?

标签 web-services

Web 服务调用具有“out”参数是否不寻常?如果是这样,为什么?

我正在使用 C# web 服务,而 webserive 消费者也将是 c# 应用程序。

最佳答案

如果您指的是 ASP.Net Web 服务中 C# 级别的 out 参数,我认为这并不奇怪。您的输出参数将简单地成为响应元素的子元素。这是一个简短的示例 Web 服务,其中包含一个具有 out 参数的 Web 方法:

[WebService(Namespace = "http://begen.name/xml/namespace/2009/10/samplewebservicev1")]
public class SampleWebServiceV1 : WebService
{
    [WebMethod]
    public void
    WebMethodWithOutParameters(out string OutParam1, out string OutParam2)
    {
        OutParam1 = "Hello";
        OutParam2 = "Web!";
    }
}

使用上述 Web 方法,SOAP 请求如下所示:
POST /SampleWebServiceV1.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://begen.name/xml/namespace/2009/10/samplewebservicev1/WebMethodWithOutParameters"

<?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" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <WebMethodWithOutParameters xmlns="http://begen.name/xml/namespace/2009/10/samplewebservicev1" />
  </soap:Body>
</soap:Envelope>

响应如下所示:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?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" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <WebMethodWithOutParametersResponse xmlns="http://begen.name/xml/namespace/2009/10/samplewebservicev1">
      <OutParam1>Hello</OutParam1>
      <OutParam2>Web!</OutParam2>
    </WebMethodWithOutParametersResponse>
  </soap:Body>
</soap:Envelope>

注意:这不会使这个问题的其他答案无效,因为他们都是从 Web 服务级别而不是 C# 级别考虑这一点的。

关于web-services - Web 服务调用具有 "out"参数是否不寻常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1590002/

相关文章:

java - Axis2 和 Web 服务

c# - 需要viber webservice或api地址

java - 通过Rest WebService上传图像文件

java - 调用 Web 服务所需的所有组件是什么

java - 用于使用 SOAP - WSDL 的命令行 java 客户端

c# - "Out of memory"Web 服务调用异常

sql-server - 'ALFKI'到底是什么意思?

xml - 不带参数的 getter 的 WSDL 类型

java - OTRS REST Java 客户端

django - 使用 SSL (https) 的网络服务的 Nginx 设置