Web 服务调用出现“out"是不寻常的吗?范围? [英] Is it unusual for a web service call to have an "out" parameter?

查看:27
本文介绍了Web 服务调用出现“out"是不寻常的吗?范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it unusual for a web service call to have an "out" parameter? If so, why?

我使用的是 C# 网络服务,而网络服务消费者也将是 C# 应用程序.

I am using C# web service and webserive consumer also will be c# app.

推荐答案

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

If you are referring to out parameters at the C# level in an ASP.Net web service, I don't think its unusual at all. Your out parameters will simply become child elements of the response element. Here's a short example web service with a single web method that has out parameters:

[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 请求如下所示:

With the above web method, the SOAP request looks like this:

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# 级别考虑这一点的.

Note: this doesn't invalidate the other answers to this question, as they were all considering this from the web service level, not the C# level.

这篇关于Web 服务调用出现“out"是不寻常的吗?范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆