locked
Change result tag in response WCF RRS feed

  • Question

  • User-725637018 posted

    Hello,

    I'm trying to remove the result tag, in a method response, using WCF.

    I've read a lot about message contracts, but it doens't seem to work out.

    Some details

    <OperationContract()>
        Function PushPersons(ByVal ValidationKey As String, ByVal License As String) As PushPersonsResult()

    <DataContract()>
    Public Class PushPersonsResult
        <DataMember()>
        Public Property Remote_Persons_id() As String
      
        <DataMember()>
        Public Property Local_Persons_id() As String
    End Class

    Call method

    Public Function PushPersons(ByVal ValidationKey As String, ByVal License As String) As PushPersonsResult() Implements cIIE.PushPersons
            Dim returnDataPatient(1) As PushPersonsResult
            Dim Test As New PushPersonsResult
            Test.Local_Persons_id = 1
            Test.Remote_Persons_id = 2
            returnDataPatient(0) = Test
          
            Dim Test2 As New PushPersonsResult
            Test2.Local_Persons_id = 0
            Test2.Remote_Persons_id = 10
            returnDataPatient(1) = Test2
    
            Return returnDataPatient
        End Function
    End Class

    XML result

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
      <s:Header />
      <s:Body>
        <PushPersonsResponse xmlns="http://tempuri.org/">
          <PushPersonsResult xmlns:a="http://schemas.datacontract.org/2004/07/IIE_WCF" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:PushPersonsResult>
              <a:Local_Persons_id>1</a:Local_Persons_id>
              <a:Remote_Persons_id>2</a:Remote_Persons_id>
            </a:PushPersonsResult>
            <a:PushPersonsResult>
              <a:Local_Persons_id>0</a:Local_Persons_id>
              <a:Remote_Persons_id>10</a:Remote_Persons_id>
            </a:PushPersonsResult>
          </PushPersonsResult>
        </PushPersonsResponse>
      </s:Body>
    </s:Envelope>

    The result tag

     <PushPersonsResult xmlns:a="http://schemas.datacontract.org/2004/07/IIE_WCF" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

    is inserted by default, however, I want to have it changed to, e.g.

     <PushPersonsList xmlns:a="http://schemas.datacontract.org/2004/07/IIE_WCF" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

    So it would look like

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
      <s:Header />
      <s:Body>
        <PushPersonsResponse xmlns="http://tempuri.org/">
          <PushPersonsResult xmlns:a="http://schemas.datacontract.org/2004/07/IIE_WCF" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:PushPersonsList>
              <a:Local_Persons_id>1</a:Local_Persons_id>
              <a:Remote_Persons_id>2</a:Remote_Persons_id>
            </a:PushPersonsResult>
            <a:PushPersonsResult>
              <a:Local_Persons_id>0</a:Local_Persons_id>
              <a:Remote_Persons_id>10</a:Remote_Persons_id>
            </a:PushPersonsResult>
          </PushPersonsResult>
        </PushPersonsList>
      </s:Body>
    </s:Envelope>


    Can anyone help me out?

    Thanks a lot!Davy

    Thursday, April 3, 2014 4:01 PM

Answers

  • User-417640953 posted

    Hi Davy,

    Thanks for your post.

    Based on your description, I see you want to change the result suffix in the response soap body.

    However, as we known, the soap response format is the body=>Response=>Result.

    That format defined in the soap protocol. So we cannot change it using wcf contract.

    So if you donot want this format, you can define custom soap message formatting like below.

    http://msdn.microsoft.com/en-us/library/dkwy2d72(v=vs.80).aspx

    Thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 8, 2014 6:42 AM

All replies

  • User364480375 posted

    see this:

    http://forums.asp.net/t/1460873.aspx

    Friday, April 4, 2014 12:49 AM
  • User-725637018 posted

    Thanks for answering.

    I found that thread before, but it's not working.

    First of all, <SoapDocumentMethod(ParameterStyle:=SoapParameterStyle.Bare), _
         WebMethod()> _

    Is not working in WCF. And I'm trying to set it up in WCF.

    However, using it in ASMX, replaces the response tag, with the result tag. So now I'm having one tag less

    <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>
        <PushPersonsResult xmlns="IEE">
          <PushPersonsResult>
            <Remote_Persons_id>string</Remote_Persons_id>
            <Local_Persons_id>string</Local_Persons_id>
            <SyncState>syncok or conflict or failed</SyncState>
          </PushPersonsResult>
          <PushPersonsResult>
            <Remote_Persons_id>string</Remote_Persons_id>
            <Local_Persons_id>string</Local_Persons_id>
            <SyncState>syncok or conflict or failed</SyncState>
          </PushPersonsResult>
        </PushPersonsResult>
      </soap:Body>
    </soap:Envelope>

    And what I want is

    <PushPersonsResponse>
    	<PushPersonsResults>
    		<PushPersonsResult>
    			<LocalPersonId>
    			<RemotePersonId>
    <SyncState></SyncState>
    		</PushPersonsResult>
    		<PushPersonsResult>
    			…
    		</PushPersonsResult>
    		…
    	</PushPersonsResults>
    </PushPersonsResponse>
    

    Friday, April 4, 2014 2:23 AM
  • User-725637018 posted

    Ok, but the code doens't have the effect I want

    [OperationContract(Name = "AOtherMethodName")]

    changed the result attribute but it it changed the method call (response name tag) too and I just want to change or remove the result tag.

    Wrong result:

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
      <s:Header />
      <s:Body>
        <AOtherMethodNameResponse xmlns="http://tempuri.org/">
          <AOtherMethodNameResult xmlns:a="http://schemas.datacontract.org/2004/07/IIE_WCF" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:PushPersonsResult>
              <a:Local_Persons_id>1</a:Local_Persons_id>
              <a:Remote_Persons_id>2</a:Remote_Persons_id>
              <a:SyncState>conflict</a:SyncState>
            </a:PushPersonsResult>
            <a:PushPersonsResult>
              <a:Local_Persons_id>0</a:Local_Persons_id>
              <a:Remote_Persons_id>10</a:Remote_Persons_id>
              <a:SyncState>syncok</a:SyncState>
            </a:PushPersonsResult>
          </AOtherMethodNameResult>
        </AOtherMethodNameResponse>
      </s:Body>
    </s:Envelope>

    I need a concrete example based on the code I wrote and the result I desire.

    Thanks!

    Friday, April 4, 2014 4:40 AM
  • User-417640953 posted

    Hi Davy,

    Thanks for your post.

    Based on your description, I see you want to change the result suffix in the response soap body.

    However, as we known, the soap response format is the body=>Response=>Result.

    That format defined in the soap protocol. So we cannot change it using wcf contract.

    So if you donot want this format, you can define custom soap message formatting like below.

    http://msdn.microsoft.com/en-us/library/dkwy2d72(v=vs.80).aspx

    Thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 8, 2014 6:42 AM