none
How do I create an Operation that receives an Xml input parameter that has an associated schema namepace RRS feed

  • Question

  • I need to create a SOAP Operation that receives and returns XML.  The XML input needs to have an associated namespace.  The only way that I have found to do this is to use a MessageContract for the input and output parameters.  Is this correct?

    The problem that I am having is that the client code that is generated does not seem to match the actual ServiceContract code.  Specifically the generated client code does not have a public method with those parameters.  Instead the public method generated accepts nothing and returns void.

    Here is the Service code -

        [ServiceContract]
        public interface IService1
        {
    
            [OperationContract]
            string GetData(int value);
    
            [OperationContract]
            CompositeType GetDataUsingDataContract(CompositeType composite);
    
            [OperationContract]
            Output DoSomething(Input input);
        }
    
        [MessageContract(WrapperNamespace = "http://ACORD.org/Standards/Life/2")]
        public class Input
        {
            public XmlDocument TxInput;
        }
    
        [MessageContract(WrapperNamespace = "http://ACORD.org/Standards/Life/2")]
        public class Output
        {
            public XmlDocument TxOutput;
        }
    
        // Use a data contract as illustrated in the sample below to add composite types to service operations.
        [DataContract]
        public class CompositeType
        {
            bool boolValue = true;
            string stringValue = "Hello ";
    
            [DataMember]
            public bool BoolValue
            {
                get { return boolValue; }
                set { boolValue = value; }
            }
    
            [DataMember]
            public string StringValue
            {
                get { return stringValue; }
                set { stringValue = value; }
            }
        }
    

    Here is the generated client code - 

    namespace WcfService2
    {
        using System.Runtime.Serialization;
        
        
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
        [System.Runtime.Serialization.DataContractAttribute(Name="CompositeType", Namespace="http://schemas.datacontract.org/2004/07/WcfService2")]
        public partial class CompositeType : object, System.Runtime.Serialization.IExtensibleDataObject
        {
            
            private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
            
            private bool BoolValueField;
            
            private string StringValueField;
            
            public System.Runtime.Serialization.ExtensionDataObject ExtensionData
            {
                get
                {
                    return this.extensionDataField;
                }
                set
                {
                    this.extensionDataField = value;
                }
            }
            
            [System.Runtime.Serialization.DataMemberAttribute()]
            public bool BoolValue
            {
                get
                {
                    return this.BoolValueField;
                }
                set
                {
                    this.BoolValueField = value;
                }
            }
            
            [System.Runtime.Serialization.DataMemberAttribute()]
            public string StringValue
            {
                get
                {
                    return this.StringValueField;
                }
                set
                {
                    this.StringValueField = value;
                }
            }
        }
    }
    
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName="IService1")]
    public interface IService1
    {
        
        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService1/GetData", ReplyAction="http://tempuri.org/IService1/GetDataResponse")]
        string GetData(int value);
        
        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService1/GetDataUsingDataContract", ReplyAction="http://tempuri.org/IService1/GetDataUsingDataContractResponse")]
        WcfService2.CompositeType GetDataUsingDataContract(WcfService2.CompositeType composite);
        
        // CODEGEN: Generating message contract since the wrapper namespace (http://ACORD.org/Standards/Life/2) of message Input does not match the default value (http://tempuri.org/)
        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService1/DoSomething", ReplyAction="http://tempuri.org/IService1/DoSomethingResponse")]
        Output DoSomething(Input request);
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    [System.ServiceModel.MessageContractAttribute(WrapperName="Input", WrapperNamespace="http://ACORD.org/Standards/Life/2", IsWrapped=true)]
    public partial class Input
    {
        
        public Input()
        {
        }
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    [System.ServiceModel.MessageContractAttribute(WrapperName="Output", WrapperNamespace="http://ACORD.org/Standards/Life/2", IsWrapped=true)]
    public partial class Output
    {
        
        public Output()
        {
        }
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    public interface IService1Channel : IService1, System.ServiceModel.IClientChannel
    {
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    public partial class Service1Client : System.ServiceModel.ClientBase<IService1>, IService1
    {
        
        public Service1Client()
        {
        }
        
        public Service1Client(string endpointConfigurationName) : 
                base(endpointConfigurationName)
        {
        }
        
        public Service1Client(string endpointConfigurationName, string remoteAddress) : 
                base(endpointConfigurationName, remoteAddress)
        {
        }
        
        public Service1Client(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(endpointConfigurationName, remoteAddress)
        {
        }
        
        public Service1Client(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(binding, remoteAddress)
        {
        }
        
        public string GetData(int value)
        {
            return base.Channel.GetData(value);
        }
        
        public WcfService2.CompositeType GetDataUsingDataContract(WcfService2.CompositeType composite)
        {
            return base.Channel.GetDataUsingDataContract(composite);
        }
        
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
        Output IService1.DoSomething(Input request)
        {
            return base.Channel.DoSomething(request);
        }
        
        public void DoSomething()
        {
            Input inValue = new Input();
            Output retVal = ((IService1)(this)).DoSomething(inValue);
        }
    }
    

    Why is the client generated code "void DoSomething()"  when it should be "output DoSomething(input)"?

     


    Thanks, -ja

    Monday, June 23, 2014 7:23 PM

Answers

  • Hi,

    Please try to add the following to your code:

    [MessageContract(WrapperNamespace = "http://ACORD.org/Standards/Life/2")]
        public class Input
        {
            [MessageHeader]
            public  XmlDocument TxInput;
        }
    
        [MessageContract(WrapperNamespace = "http://ACORD.org/Standards/Life/2")]
        public class Output
        {
            [MessageBodyMember]
            public XmlDocument TxOutput;
        }

    Besides, the following article may help you understand more about the message contract:
    #How to Implement Message Contract in WCF:
    http://www.c-sharpcorner.com/UploadFile/788083/how-to-implement-message-contract-in-wcf/ .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 24, 2014 6:46 AM
    Moderator