Solved

Need help in consuming web Service method

Posted on 2009-03-29
6
424 Views
Last Modified: 2013-11-26
Hello Experts ,
I am creating a webmethod which takes input custom object . I have given a simplifed sample of WSDL where I am facing Problem.My WSDL gets all classes and types (Filter1,Filter2) in it but When I add a web reference from visual Studio it only gives me Filter2 and No Filter1 :(
But If I use WebService studio to generate request It does Filter1 and Filter2 too.
I have attached my class file to for request.
TestWSDL.txt
0
Comment
Question by:EmiliJ
  • 3
  • 2
6 Comments
 
LVL 19

Expert Comment

by:daveamour
ID: 24016158
Can we se your C# code.  With text, no need to attach as a file, just click Attach Code Snippet below.
0
 
LVL 9

Expert Comment

by:ripahoratiu
ID: 24016916
Use XMLInclude in your service, and include Filter1
Where the method uses Filter1 just set a
[XmlInclude(typeof(Filter1))]  
0
 

Accepted Solution

by:
EmiliJ earned 0 total points
ID: 24018181
Here is C# class
// Copyright 2004, Microsoft Corporation
// Sample Code - Use restricted to terms of use defined in the accompanying license agreement (EULA.doc)

//--------------------------------------------------------------
// Autogenerated by XSDObjectGen version 1.4.4.0
// Schema file: xsd
// Creation Date: 1/1/2009 8:52:52 PM
//--------------------------------------------------------------

using System;
using System.Xml.Serialization;
using System.Collections;
using System.Collections.Generic;
using System.Xml.Schema;
using System.ComponentModel;

namespace Testing
{

      public struct Declarations
      {
            public const string SchemaVersion = "http://tempuri.org/XMLSchema.xsd";
      }


      [Serializable]
      [EditorBrowsable(EditorBrowsableState.Advanced)]
      public class codeCollection : List<string>
      {
            
      }

      [Serializable]
      [EditorBrowsable(EditorBrowsableState.Advanced)]
      public class idCollection : List<int>
      {
    }



      [XmlType(TypeName="Filter1",Namespace=Declarations.SchemaVersion),Serializable]
      [EditorBrowsable(EditorBrowsableState.Advanced)]
      public class Filter1
      {
            
            [XmlElement(Type=typeof(int),ElementName="id",IsNullable=false,Form=XmlSchemaForm.Qualified,DataType="int",Namespace=Declarations.SchemaVersion)]
            [EditorBrowsable(EditorBrowsableState.Advanced)]
            public idCollection __idCollection;
            
            [XmlIgnore]
            public idCollection idCollection
            {
                  get
                  {
                        if (__idCollection == null) __idCollection = new idCollection();
                        return __idCollection;
                  }
                  set {__idCollection = value;}
            }

            public Filter1()
            {
            }
      }


      [XmlType(TypeName="Filter2",Namespace=Declarations.SchemaVersion),Serializable]
      [EditorBrowsable(EditorBrowsableState.Advanced)]
      public class Filter2
      {
            
      }

    [XmlInclude(typeof(Filter1))]  
    [XmlInclude(typeof(Filter2))]  
      [XmlType(TypeName="param",Namespace=Declarations.SchemaVersion),Serializable]
      [EditorBrowsable(EditorBrowsableState.Advanced)]
      public class param
      {

            [XmlElement(Type=typeof(Filter1),ElementName="filterA",IsNullable=false,Form=XmlSchemaForm.Qualified,Namespace=Declarations.SchemaVersion)]
            [EditorBrowsable(EditorBrowsableState.Advanced)]
            public Filter1 __filterA;
            
            [XmlIgnore]
            public Filter1 filterA
            {
                  get
                  {
                        if (__filterA == null) __filterA = new Filter1();            
                        return __filterA;
                  }
                  set {__filterA = value;}
            }

            [XmlElement(Type=typeof(Filter2),ElementName="filterB",IsNullable=false,Form=XmlSchemaForm.Qualified,Namespace=Declarations.SchemaVersion)]
            [EditorBrowsable(EditorBrowsableState.Advanced)]
            public Filter2 __filterB;
            
            [XmlIgnore]
            public Filter2 filterB
            {
                  get
                  {
                        if (__filterB == null) __filterB = new Filter2();            
                        return __filterB;
                  }
                  set {__filterB = value;}
            }

            public param()
            {
            }
      }
}
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

Author Comment

by:EmiliJ
ID: 24018193
I tried adding XmlInclude and updated web reference too but no luck
0
 
LVL 9

Assisted Solution

by:ripahoratiu
ripahoratiu earned 20 total points
ID: 24018495
And configure the WebService Reference -> Collection Type to generic collection


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Xml.Schema;
 
namespace WebService2
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {
 
        [WebMethod]
        public param HelloWorld(int id)
        {
            param p = new param();
            p.__filterA = new Filter1();
            p.__filterA.idCollection = new idCollection();
            p.filterA.idCollection.Add(1);
            p.filterA.idCollection.Add(2);
            p.filterA.idCollection.Add(3);
            p.filterA.idCollection.Add(4);
            p.filterA.idCollection.Add(5);
            p.__filterB = new Filter2();
            return p;
        }
    }
 
      public struct Declarations
      {
            public const string SchemaVersion = "http://tempuri.org/XMLSchema.xsd";
      }
 
 
      [Serializable]
      [EditorBrowsable(EditorBrowsableState.Advanced)]
      public class codeCollection : List<string>
      {
            
      }
 
      [XmlType(TypeName = "idCollection", Namespace = Declarations.SchemaVersion), Serializable]
      public class idCollection : List<int>
      {
    }
 
 
      [XmlType(TypeName = "Filter1", Namespace = Declarations.SchemaVersion), Serializable]
      public class Filter1
      {
            
            private idCollection __idCollection;
            public idCollection idCollection
            {
                  get
                  {
                        if (__idCollection == null) __idCollection = new idCollection();
                        return __idCollection;
                  }
                  set {__idCollection = value;}
            }
 
            public Filter1()
            {
            }
      }
 
 
      [XmlType(TypeName="Filter2",Namespace=Declarations.SchemaVersion),Serializable]
      [EditorBrowsable(EditorBrowsableState.Advanced)]
      public class Filter2
      {
            
      }
 
    [XmlInclude(typeof(Filter1))]  
    [XmlInclude(typeof(Filter2))]  
      [XmlType(TypeName="param",Namespace=Declarations.SchemaVersion),Serializable]
      [EditorBrowsable(EditorBrowsableState.Advanced)]
      public class param
      {
 
            [XmlElement(Type=typeof(Filter1),ElementName="filterA",IsNullable=false,Form=XmlSchemaForm.Qualified,Namespace=Declarations.SchemaVersion)]
            [EditorBrowsable(EditorBrowsableState.Advanced)]
            public Filter1 __filterA;
            
            [XmlIgnore]
            public Filter1 filterA
            {
                  get
                  {
                        if (__filterA == null) __filterA = new Filter1();            
                        return __filterA;
                  }
                  set {__filterA = value;}
            }
 
            [XmlElement(Type=typeof(Filter2),ElementName="filterB",IsNullable=false,Form=XmlSchemaForm.Qualified,Namespace=Declarations.SchemaVersion)]
            [EditorBrowsable(EditorBrowsableState.Advanced)]
            public Filter2 __filterB;
            
            [XmlIgnore]
            public Filter2 filterB
            {
                  get
                  {
                        if (__filterB == null) __filterB = new Filter2();            
                        return __filterB;
                  }
                  set {__filterB = value;}
            }
 
            public param()
            {
            }
      }
}

Open in new window

0
 
LVL 9

Expert Comment

by:ripahoratiu
ID: 24018555
Note: "Serializable" means nothing in XML serializable context of web services. Indeed, including filter1 and 2 does nothing as long as they are in the same assembly and namespace with the param class.
I'm not sure why do you (XML)ignore the properties and expose the fields... Usually the other way is suitable.

I think that if you would simply create the classes with no XML attributes at all, and with private fields wrapped in public properties, that would simply work with no problems.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question