none
Generated WCF Service from WSDL RRS feed

  • Question

  • Hi,

    I have a Mock Service, now I want to Generatea wcf Service from that wsdl.

    Using that wsdl I have Generated Classes using svcutil which s like below

    //------------------------------------------------------------------------------
    // <auto-generated>
    //     This code was generated by a tool.
    //     Runtime Version:4.0.30319.42000
    //
    //     Changes to this file may cause incorrect behavior and will be lost if
    //     the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------
    
    
    
    using System.ServiceModel;
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(Namespace="http://LMessages.org/", ConfigurationName="Service1")]
    public interface Service1
    {
        
        [System.ServiceModel.OperationContractAttribute(Action="Post")]
        [System.ServiceModel.XmlSerializerFormatAttribute()]
        PostResponse Post(PostRequest request);
    
    
    }
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.18020")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://LMessages.Schemas.DestSchema")]
    public partial class DestDestination
    {
        
        private string gfbcField;
        
        private string tyghvgField;
        
        private DestDestinationFC[] fcField;
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
        public string gfbc
        {
            get
            {
                return this.gfbcField;
            }
            set
            {
                this.gfbcField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
        public string tyghvg
        {
            get
            {
                return this.tyghvgField;
            }
            set
            {
                this.tyghvgField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("fc", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
        public DestDestinationFC[] fc
        {
            get
            {
                return this.fcField;
            }
            set
            {
                this.fcField = value;
            }
        }
    }
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.18020")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://LMessages.Schemas.DestSchema")]
    public partial class DestDestinationFC
    {
        
        private string fieldField;
        
        private string hjnbField;
        
        private DestDestinationFCGhv[] ghvField;
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
        public string Field
        {
            get
            {
                return this.fieldField;
            }
            set
            {
                this.fieldField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
        public string hjnb
        {
            get
            {
                return this.hjnbField;
            }
            set
            {
                this.hjnbField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("ghv", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
        public DestDestinationFCGhv[] ghv
        {
            get
            {
                return this.ghvField;
            }
            set
            {
                this.ghvField = value;
            }
        }
    }
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.18020")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://LMessages.Schemas.DestSchema")]
    public partial class DestDestinationFCGhv
    {
        
        private string gvField;
        
        private string jhField;
        
        private string hjbField;
        
        private string vvnbField;
        
        private string gbField;
        
        private string gvhField;
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
        public string gv
        {
            get
            {
                return this.gvField;
            }
            set
            {
                this.gvField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
        public string jh
        {
            get
            {
                return this.jhField;
            }
            set
            {
                this.jhField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
        public string hjb
        {
            get
            {
                return this.hjbField;
            }
            set
            {
                this.hjbField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
        public string vvnb
        {
            get
            {
                return this.vvnbField;
            }
            set
            {
                this.vvnbField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=4)]
        public string gb
        {
            get
            {
                return this.gbField;
            }
            set
            {
                this.gbField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=5)]
        public string gvh
        {
            get
            {
                return this.gvhField;
            }
            set
            {
                this.gvhField = value;
            }
        }
    }
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.18020")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://LMessages.Schemas.DestDestination")]
    public partial class DestDestinationDestination
    {
        
        private string edwField;
        
        private string gftbfField;
        
        private string fieldField;
        
        private DestDestinationDestinationDS[] dsField;
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
        public string edw
        {
            get
            {
                return this.edwField;
            }
            set
            {
                this.edwField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
        public string gftbf
        {
            get
            {
                return this.gftbfField;
            }
            set
            {
                this.gftbfField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
        public string Field
        {
            get
            {
                return this.fieldField;
            }
            set
            {
                this.fieldField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("ds", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
        public DestDestinationDestinationDS[] ds
        {
            get
            {
                return this.dsField;
            }
            set
            {
                this.dsField = value;
            }
        }
    }
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.18020")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://LMessages.Schemas.DestDestination")]
    public partial class DestDestinationDestinationDS
    {
        
        private string fdField;
        
        private string vdField;
        
        private string cField;
        
        private string xcxzField;
        
        private DestDestinationDestinationDSCC[] ccField;
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
        public string fd
        {
            get
            {
                return this.fdField;
            }
            set
            {
                this.fdField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
        public string vd
        {
            get
            {
                return this.vdField;
            }
            set
            {
                this.vdField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(" c", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
        public string c
        {
            get
            {
                return this.cField;
            }
            set
            {
                this.cField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
        public string xcxz
        {
            get
            {
                return this.xcxzField;
            }
            set
            {
                this.xcxzField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("cc", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=4)]
        public DestDestinationDestinationDSCC[] cc
        {
            get
            {
                return this.ccField;
            }
            set
            {
                this.ccField = value;
            }
        }
    }
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.18020")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://LMessages.Schemas.DestDestination")]
    public partial class DestDestinationDestinationDSCC
    {
        
        private string vcField;
        
        private string dsField;
        
        private string bhField;
        
        private string ccField;
        
        private string cvcvField;
        
        private string ccvField;
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
        public string vc
        {
            get
            {
                return this.vcField;
            }
            set
            {
                this.vcField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
        public string ds
        {
            get
            {
                return this.dsField;
            }
            set
            {
                this.dsField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
        public string bh
        {
            get
            {
                return this.bhField;
            }
            set
            {
                this.bhField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
        public string cc
        {
            get
            {
                return this.ccField;
            }
            set
            {
                this.ccField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=4)]
        public string cvcv
        {
            get
            {
                return this.cvcvField;
            }
            set
            {
                this.cvcvField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(" ccv", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=5)]
        public string ccv
        {
            get
            {
                return this.ccvField;
            }
            set
            {
                this.ccvField = value;
            }
        }
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
    public partial class PostRequest
    {
        
        [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://LMessages.Schemas.DestSchema", Order=0)]
        [System.Xml.Serialization.XmlArrayItemAttribute("Destination", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
        public DestDestination[] Dest;
        
        public PostRequest()
        {
        }
        
        public PostRequest(DestDestination[] Dest)
        {
            this.Dest = Dest;
        }
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
    public partial class PostResponse
    {
        
        [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://LMessages.Schemas.DestDestination", Order=0)]
        [System.Xml.Serialization.XmlArrayItemAttribute("Destination", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
        public DestDestinationDestination[] DestDestination;
        
        public PostResponse()
        {
        }
        
        public PostResponse(DestDestinationDestination[] DestDestination)
        {
            this.DestDestination = DestDestination;
        }
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public interface Service1Channel : Service1, System.ServiceModel.IClientChannel
    {
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public partial class Service1Client : System.ServiceModel.ClientBase<Service1>, Service1
    {
        
        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 PostResponse Post(PostRequest request)
        {
            return base.Channel.Post(request);
        }
    
       
    }
    

    Then I have added a Service to inherit this which is like below

    using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace MockService { // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "MyMock" in code, svc and config file together. // NOTE: In order to launch WCF Test Client for testing this service, please select MyMock.svc or MyMock.svc.cs at the Solution Explorer and start debugging. public class MyMock : Service1 { public void DoWork() { } public PostResponse Post(PostRequest request) { PostResponse postt = new PostResponse();

         postt.DestDestination[1].edw =

    "fgf";

                postt.DestDestination[1].Field =

    "sdcs";

                postt.DestDestination[1].gftbf =

    "cs";

    return postt; } } }


    when try to test it at the first step(

    postt.DestDestination[1].edw =

    "fgf";)

    I always get a Null Reference Exception. Can you Please help me with this?

    Thanks,

    Sujith.

    Wednesday, October 26, 2016 2:43 PM

Answers

  • Hello sujith reddy komma,

    Try initializing the DestDesination array first.  One way to approach this would be 

    PostResponse r = new PostResponse
    {
        DestDestination = new DestDestinationDestination[]
        {
            new DestDestinationDestination
            {
                edw = "fgf",
                Field = "sdcs",
                gftbf = "cs"
            },
            new DestDestinationDestination
            {
                edw = "adsf",
                Field = "adsf",
                gftbf = "cs"
            },
        }
    };


    Cheers, Jeff

    Wednesday, October 26, 2016 7:04 PM
  • Hi Sujith,

    >> How can I achieve it to get 100 Records of Destination?

    For this requirement, I suggest you try something like below:

            DestDestinationDestination[] cm=new DestDestinationDestination[100];
            DestDestinationDestination c = new DestDestinationDestination
            {
                edw = "fgf",
                Field = "sdcs",
                gftbf = "cs"
            };
            for (int i = 0; i < 100; i++)
            {
                cm[i] = c;
            }
             PostResponse r = new PostResponse{DestDestination =cm};

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 27, 2016 9:43 AM

All replies

  • Hello sujith reddy komma,

    Try initializing the DestDesination array first.  One way to approach this would be 

    PostResponse r = new PostResponse
    {
        DestDestination = new DestDestinationDestination[]
        {
            new DestDestinationDestination
            {
                edw = "fgf",
                Field = "sdcs",
                gftbf = "cs"
            },
            new DestDestinationDestination
            {
                edw = "adsf",
                Field = "adsf",
                gftbf = "cs"
            },
        }
    };


    Cheers, Jeff

    Wednesday, October 26, 2016 7:04 PM
  • Hi Jeff,

    Thanks for the Reply but I need to send around 100 rows

    the above code will be for 2 rows,Data can be anything I thought of using a for loop to iterate,but its not making me use it.

    Can you Help me how can I do that?

    Thanks,

    Sujith.

    Thursday, October 27, 2016 7:00 AM
  • Hi Sujith,

    I think Jeff provide a demo code, you could send data with your requirement. Did you get any error while you try the code from Jeff?

    Based on your code, you create your own wcf service which is inherit from Service1. For your error message, it is caused by that you define a PostResponse objet, but you did not set any value for it before this line “postt.DestDestination[1].edw = "fgf";”. Before setting edw, you need to add DestDestination which is provided by Jeff.

    Based on your description, you want to return 100 rows, but in your code, you did not achieve this. It would be helpful if you could share us more information about what you want to return.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 27, 2016 7:43 AM
  • Hi Edward,

    I did run the below Code and I was able to get the Resposs back

          public PostResponse Post(PostRequest request)
            {
               
               
                    PostResponse r = new PostResponse
    {
        DestDestination = new DestDestinationDestination[]
        {
            new DestDestinationDestination
            {
                edw = "fgf",
                Field = "sdcs",
                gftbf = "cs"
            },
            new DestDestinationDestination
            {
                edw = "adsf",
                Field = "adsf",
                gftbf = "cs"
            },
        }
    };
                   
                    return r;
                
                }

    it will give me an o/p like below

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
       <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <DestDestination xmlns="http://LMessages.Schemas.DestDestination">
             <Destination xmlns="">
                <edw>fgf</edw>
                <gftbf>cs</gftbf>
                <Field>sdcs</Field>
             </Destination>
             <Destination xmlns="">
                <edw>adsf</edw>
                <gftbf>cs</gftbf>
                <Field>adsf</Field>
             </Destination>
          </DestDestination>
       </s:Body>
    </s:Envelope>

    but my requirement is I want probably 100 Records of Destination,

    Data Can be anything.

    so I have to use a Loop,if I write something like below.i should be getting 10 Records but I get Argument out of Range Exception.

    for (int i = 1; i < 10; i++)
                    {
                             r.DestDestination[i].edw = "fgf";

                r.DestDestination[i].Field = "sdcs";

                r.DestDestination[i].gftbf = "cs";

                    }

    How can I achieve it to get 100 Records of Destination?

    Thanks,

    Sujith.

    Thursday, October 27, 2016 8:04 AM
  • Hi Sujith,

    >> How can I achieve it to get 100 Records of Destination?

    For this requirement, I suggest you try something like below:

            DestDestinationDestination[] cm=new DestDestinationDestination[100];
            DestDestinationDestination c = new DestDestinationDestination
            {
                edw = "fgf",
                Field = "sdcs",
                gftbf = "cs"
            };
            for (int i = 0; i < 100; i++)
            {
                cm[i] = c;
            }
             PostResponse r = new PostResponse{DestDestination =cm};

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 27, 2016 9:43 AM