gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 02:58:57 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com