5

I know this questions has been asked before but I could not find my answer anywhere.

the thing is I have below code on my asmx file:

namespace IrancellSmsServer
{
    [SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
    [WebService(Namespace =   "http://www.csapi.org/schema/parlayx/data/sync/v1_0/local")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]

    public class SoapServer : System.Web.Services.WebService
    {
        [WebMethod]
        public syncOrderRelationResponse syncOrderRelation(
            Sync.UserID userID,
            string spID,
            string productID,
            string serviceID,
            string serviceList,
            int updateType,
            string updateTime,
            string updateDesc,
            string effectiveTime,
            string expiryTime,
            item[] extensionInfo
            )
        {    
            syncOrderRelationResponse a = new syncOrderRelationResponse();
            a.result = 0;
            a.resultDescription = "OK";         
            return a;
        }
     }
}

And this is the result:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <syncOrderRelationResponse xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">
      <syncOrderRelationResult>   //dont want this
        <result>0</result>
        <resultDescription>OK</resultDescription>
      </syncOrderRelationResult>  //dont want this
    </syncOrderRelationResponse>
  </soap:Body>
</soap:Envelope

the problem is I dont want that extra <syncOrderRelationResult> tag that .net created automatically. I want it completely remove. I have tried [SoapDocumentMethod(ParameterStyle=SoapParameterStyle.Bare)]

but no luck it tels me I should have one parameter. is there any way I could do this?

expected result:

 <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <soap:Body>
        <syncOrderRelationResponse xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">
            <result>0</result>
            <resultDescription>OK</resultDescription>
        </syncOrderRelationResponse>
      </soap:Body>
    </soap:Envelope

here is the code of syncOrderRelationResponse:

namespace IrancellSmsServer.Sync {
    using System;
    using System.Web.Services;
    using System.Diagnostics;
    using System.Web.Services.Protocols;
    using System.Xml.Serialization;
    using System.ComponentModel;

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.6.1055.0")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Web.Services.WebServiceBindingAttribute(Name="DataSyncBinding", Namespace="http://www.csapi.org/wsdl/parlayx/data/sync/v1_0/service")]
    public partial class DataSyncService : System.Web.Services.Protocols.SoapHttpClientProtocol {

        private bool useDefaultCredentialsSetExplicitly;

        /// <remarks/>
        public DataSyncService() {
            this.Url = global::IrancellSmsServer.Properties.Settings.Default.IrancellSmsServer_Sync_DataSyncService;
            if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
                this.UseDefaultCredentials = true;
                this.useDefaultCredentialsSetExplicitly = false;
            }
            else {
                this.useDefaultCredentialsSetExplicitly = true;
            }
        }

        public new string Url {
            get {
                return base.Url;
            }
            set {
                if ((((this.IsLocalFileSystemWebService(base.Url) == true) 
                            && (this.useDefaultCredentialsSetExplicitly == false)) 
                            && (this.IsLocalFileSystemWebService(value) == false))) {
                    base.UseDefaultCredentials = false;
                }
                base.Url = value;
            }
        }

        public new bool UseDefaultCredentials {
            get {
                return base.UseDefaultCredentials;
            }
            set {
                base.UseDefaultCredentials = value;
                this.useDefaultCredentialsSetExplicitly = true;
            }
        }


        /// <remarks/>
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
        [return: System.Xml.Serialization.XmlElementAttribute("syncOrderRelationResponse", Namespace="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local")]
        public syncOrderRelationResponse syncOrderRelation([System.Xml.Serialization.XmlElementAttribute("syncOrderRelation", Namespace="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local")] syncOrderRelation syncOrderRelation1) {
            object[] results = this.Invoke("syncOrderRelation", new object[] {
                        syncOrderRelation1});
            return ((syncOrderRelationResponse)(results[0]));
        }


        /// <remarks/>
        public void syncOrderRelationAsync(syncOrderRelation syncOrderRelation1, object userState) {
            if ((this.syncOrderRelationOperationCompleted == null)) {
                this.syncOrderRelationOperationCompleted = new System.Threading.SendOrPostCallback(this.OnsyncOrderRelationOperationCompleted);
            }
            this.InvokeAsync("syncOrderRelation", new object[] {
                        syncOrderRelation1}, this.syncOrderRelationOperationCompleted, userState);
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.1055.0")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local")]
    public partial class syncOrderRelationResponse {

        private int resultField;

        private string resultDescriptionField;

        //private item[] extensionInfoField;

        /// <remarks/>
        public int result {
            get {
                return this.resultField;
            }
            set {
                this.resultField = value;
            }
        }

        /// <remarks/>
        public string resultDescription {
            get {
                return this.resultDescriptionField;
            }
            set {
                this.resultDescriptionField = value;
            }
        }

        /// <remarks/>
        //[System.Xml.Serialization.XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
        //public item[] extensionInfo {
        //    get {
        //        return this.extensionInfoField;
        //    }
        //    set {
        //        this.extensionInfoField = value;
        //    }
        //}
    }



        /// <remarks/>
        public syncOrderRelationResponse Result {
            get {
                this.RaiseExceptionIfNecessary();
                return ((syncOrderRelationResponse)(this.results[0]));
            }
        }
    }
    }
}
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291

6 Answers6

3

Add this on top of your method

[WebMethod]
[return: XmlElement("syncOrderRelationResponse")]
[SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)]
TheJonz
  • 394
  • 2
  • 11
2

Add this on top of your method

[WebMethod]
[return: XmlElement("syncOrderRelationResponse")]
[SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)]

and change it from:

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

to :

[WebServiceBinding(ConformsTo = WsiProfiles.None)]

and You can also use this link : WOOw!

https://stackoverflow.com/a/29855766/8517391

Y.Ehsani
  • 21
  • 5
1

I had the same requirement and after digging for a while I came with a workaround as follows: As mentioned before, in order to remove the result tag, do the following:

[WebMethod]
[return: XmlElement("syncOrderRelationResponse")]
[SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)]
//the syncOrderRelation method goes here ...

This will result in the output as follows:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <syncOrderRelationResponse 
       xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">
        <result>0</result>
        <resultDescription>OK</resultDescription>
    </syncOrderRelationResponse>
  </soap:Body>
</soap:Envelope

as you desired. However, It will also strip the method name syncOrderRelation in the request because ParameterStyle is applied to both request and response elements.

Workaround: Create a Class named syncOrderRelation and put all the parameters from syncOrderRelation request method into the class you just created and use an Object of syncOrderRelation class as a parameter for the method. Done!

1

implementing SoapCore (like wcf) in my case write this

[MessageContract(IsWrapped = false)]

to returned class head and write this

[return: XmlElement("availabilityResponse")]

to adapter class head

Hamit YILDIRIM
  • 4,224
  • 1
  • 32
  • 35
  • Are you using XmlSerializer or DataContractSerializer? This didn't work for me with DataContractSerilizer, and it caused XmlSerializer to error out. Adding `[System.ServiceModel.MessageBodyMember]` to tthe properties of my request/resposne objects fixed *that* error, but then the root element became the first property of my request/response objects. – neilsimp1 Nov 21 '20 at 18:29
  • 1
    See https://github.com/DigDes/SoapCore/issues/550 for a longer explanation. – neilsimp1 Nov 21 '20 at 19:05
  • 1
    I remember that it should be datacontract serializor – Hamit YILDIRIM Nov 21 '20 at 20:04
0

It is not possible to remove this result. At least it is not documented.

However you can modify this name via the return attribute:

An example to name element 'return'

I know this is may not be directly helpful for you (as you want to flatten the structure), but since this is not really a standard way, this can be helpful anyway to know that you can at least modify the name of the result tag.

Peter Stegnar
  • 12,615
  • 12
  • 62
  • 80
0
  1. If you want to change <syncOrderRelationResult> to <carResult>, just add [XmlRoot("carResult")] to your object, not your function / method. Here it's sample :

[XmlRoot("carResult")] public class ObjectCar { public string model; public string color; }

or add [return: System.Xml.Serialization.XmlElementAttribute("carResult")] to your function / method :

[WebMethod] [return: System.Xml.Serialization.XmlElementAttribute("carResult")] public string syncOrderRelation(string a) { return a; }

  1. If you want to change <syncOrderRelationResponse ..> to <YourFunctionName ..>, just add [SoapDocumentMethodAttribute(ResponseElementName = "YourFunctionName")] to your function / method :

[WebMethod] [return: System.Xml.Serialization.XmlElementAttribute("carResult")][SoapDocumentMethodAttribute(ResponseElementName = "YourFunctionName")] public string syncOrderRelation(string a) { return a; }

hope it's help

Yosep Tito
  • 737
  • 6
  • 7