I am creating a SOAP Web Service using C# ASMX. I have one method which has 3 parameters. The generated WSDL created a complex type by default. The Complex type is called HelloWorld. I want to attach the 3 parameters directly to the Method's root node. How to achieve that in asmx.
Here is the generated WSDL from my Web Service
<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>
What i want to happen is the following
<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>
Here is my Web Service class
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;
}
}
}
Found the fix. It is called soapParameterStyle
[WebMethod]
[SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)]
Additionally, we have to switch off the wsi profiles to None.
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
parameterStyle - Specifies how the method parameters, which correspond to message parts in a WSDL contract, are placed into the SOAP message body.
A parameter style of BARE means that each parameter is placed into the message body as a child element of the message root.
A parameter style of WRAPPED means that all of the input parameters are wrapped into a single element on a request message and that all of the output parameters are wrapped into a single element in the response message.