Search code examples
c#asp.netasmx

C# Web Method In Specific Format


When creating a web method in an ASMX file of a C# web application, the associated WSDL is of this format:

<Envelope>
  <Header/>
  <Body>
    <WebMethodName>
      <WebMethodArgumentName>
        <WebMethodArgumentType>

I need to have it like this:

<Envelope>
  <Header/>
  <Body>
    <WebMethodName>
      <WebMethodArgumentType>

Or like this:

<Envelope>
  <Header/>
  <Body>
    <WebMethodArgumentName>
      <WebMethodArgumentType>

This is because the client sends the request in that format, so I need to control the name of the outer tag, and the only way I can think of is by changing the name of the web method or the web method argument, but in order to do that, I need to have only one of those tags.

By the way, I am generating the code with svcutil.exe (wsdl.exe produces the same result) like this:

svcutil /language:C# /out:IWebServiceName.cs /n:*,Web.Service.Namespace ^
..\XSD\SomeXsd.xsd ^
..\XSD\AnotherXsd.xsd ^
..\WSDL\TheWsdl.wsdl

How can I accomplish this?

Thanks!


Solution

  • It's been a while since I asked this question, but finally got the anwser: decorate the web method with an annotation like this:

    [SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)]

    According to the docs, there are three members of the enumeration:

    Bare, Default, Wrapped

    Wrapped is the default, which encapsulates the parameters.

    I was looking for Bare, which places the parameters directly following the Body element of a SOAP request or SOAP response.

    Hope it helps to someone dealing with this problem like I Was.