c# - ASMX SOAP Web 服务创建复杂类型而不是简单类型

标签 c# asp.net wcf asmx

我正在使用 C# ASMX 创建一个 SOAP Web 服务。我有一种方法有 3 个参数。 生成的 WSDL 默认创建了一个复杂类型。 Complex 类型称为 HelloWorld。我想将 3 个参数直接附加到方法的根节点。如何在 asmx 中实现这一点。

这是从我的 Web 服务生成的 WSDL

<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="HelloWorld">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="userid" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="data" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="HelloWorldResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="HelloWorldSoapIn">
<wsdl:part name="parameters" element="tns:HelloWorld"/>
</wsdl:message>
<wsdl:message name="HelloWorldSoapOut">
<wsdl:part name="parameters" element="tns:HelloWorldResponse"/>
</wsdl:message>

我想要发生的是以下内容

<message name="resultIn">
<part name="userid" type="xsd:string"/>
<part name="password" type="xsd:string"/>
<part name="data" type="xsd:string"/>
</message>
<message name="resultOut">
<part name="return" type="xsd:string"/>
</message>

这是我的 Web 服务类

namespace soapWebService
{
    /// <summary>
    /// Summary description for i3DrugScreenSOAP
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class testSOAP : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld(String userid, String password,String data)
        {
            return userid + password + data;
        }
    }
}

最佳答案

找到修复。它被称为 soapParameterStyle

[WebMethod]
[SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)]

此外,我们必须将 wsi 配置文件关闭为无。

[WebServiceBinding(ConformsTo = WsiProfiles.None)]

parameterStyle - 指定方法参数(对应于 WSDL 协定中的消息部分)如何放置到 SOAP 消息正文中。

BARE 参数样式表示每个参数作为消息根的子元素放入消息体中。

WRAPPED 的参数样式意味着所有输入参数都被包装到请求消息的单个元素中,并且所有的 输出参数被包装到响应消息中的单个元素中。

关于c# - ASMX SOAP Web 服务创建复杂类型而不是简单类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58490668/

相关文章:

c# - Accordion 选项卡在 dotnetnuke 中不起作用

asp.net - Base64字符串压缩

c# - 服务合约中的构造函数逻辑

c# - 异步/等待 - 等待未按预期举行

c# - 为什么 Microsoft.Build.Evaluation 在 64 位 PC 上将 $(ProgramFiles) 评估为 "c:\program files"?

c# - 查找集合交集并排除

wcf - 为 wsHttpBinding 配置 WCF

c# - 无授权 header

javascript - 在 asp.net 中,javascript 或 jquery 是否具有 Server.UrlEncode() 方法

c# - Silverlight/C# - 动态加载 WCF 数据的最佳方式?