none
Return multiple values from webservice SOAP response structure RRS feed

  • Question

  • I have defined new class and returning it with webservice:

            public class MyData
            {
                public string Data { get; set; }
                public string Data1 { get; set; }
            }
    
            [WebMethod]
            public MyData testing(string testId)
            {
    
                MyData NewData = new MyData();
    
                return NewData;
            }

    SOAP response  is:

      <soap:Body>
        <testingResponse xmlns="http://test.local/">
          <testingResult>
            <Data>string</Data>
            <Data1>string</Data1>
          </testingResult>
        </testingResponse>
      </soap:Body>

    How can I get response structure like:

      <soap:Body>
        <testingResponse xmlns="http://test.local/">
          <Data>string</Data>
          <Data1>string</Data1>
        </testingResponse>
      </soap:Body>


    • Edited by AldisB_LV Friday, July 17, 2015 9:57 AM
    Friday, July 17, 2015 8:07 AM

Answers

  • Hi AldisB_LV,

    Ok, I suggest you can add this attribute in your code, as shown below:

    [SoapDocumentService(ParameterStyle = SoapParameterStyle.Bare)]

     public MyData testing(string testId)
        {
            MyData NewData = new MyData();
            return NewData;
        }

    For more information, please refer to the following article:

    1.How to: Control Whether Web Service Method Parameters Are Enclosed in an Extra Element

    https://msdn.microsoft.com/en-us/library/bb559021(v=vs.85).aspx

    I hope that will be helpful to you.

    Best Regards,

    Tracy Dj


    Best Regards, Tracy Dj

    • Marked as answer by AldisB_LV Wednesday, July 22, 2015 10:01 AM
    Wednesday, July 22, 2015 9:29 AM
    Moderator
  • Hi AldisB_LV,

    According to this case, I'd like to suggest you can use Restful  WCF Service,

    Then, you can control your returned message structure.You can modify your code

    like below: 

    [ServiceContract]
        public interface IService1
        {
      [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,ResponseFormat =         WebMessageFormat.Xml, UriTemplate =       "GetData")]
         public MyData testing(string testId)
         {

            MyData NewData = new MyData();

            return NewData;
         }
       }  

    For more infromation,please refer to the following articale:

    1.Create RESTful WCF Service API: Step By Step Guide

    http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide

    I hope that will be helpful to you.

    Best Regards,

    Tracy Dj



    Monday, July 20, 2015 7:41 AM
    Moderator

All replies

  • Hi AldisB_LV,

    According to this case, I'd like to suggest you can use Restful  WCF Service,

    Then, you can control your returned message structure.You can modify your code

    like below: 

    [ServiceContract]
        public interface IService1
        {
      [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,ResponseFormat =         WebMessageFormat.Xml, UriTemplate =       "GetData")]
         public MyData testing(string testId)
         {

            MyData NewData = new MyData();

            return NewData;
         }
       }  

    For more infromation,please refer to the following articale:

    1.Create RESTful WCF Service API: Step By Step Guide

    http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide

    I hope that will be helpful to you.

    Best Regards,

    Tracy Dj



    Monday, July 20, 2015 7:41 AM
    Moderator
  • Thanks for replay.

    Rewriting all solution in WCF would be quit painful :(

    So there is no way to achieve it with web service ?

    Tuesday, July 21, 2015 2:18 PM
  • Hi AldisB_LV,

    Ok, I suggest you can add this attribute in your code, as shown below:

    [SoapDocumentService(ParameterStyle = SoapParameterStyle.Bare)]

     public MyData testing(string testId)
        {
            MyData NewData = new MyData();
            return NewData;
        }

    For more information, please refer to the following article:

    1.How to: Control Whether Web Service Method Parameters Are Enclosed in an Extra Element

    https://msdn.microsoft.com/en-us/library/bb559021(v=vs.85).aspx

    I hope that will be helpful to you.

    Best Regards,

    Tracy Dj


    Best Regards, Tracy Dj

    • Marked as answer by AldisB_LV Wednesday, July 22, 2015 10:01 AM
    Wednesday, July 22, 2015 9:29 AM
    Moderator