Solved

Need help in consuming web Service method

Posted on 2009-03-29
6
422 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

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

Assisted Solution

by:ripahoratiu
ripahoratiu earned 20 total points
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

New Relic recently released its Synthetics product that allows for the creation of performance monitors that periodically test a site's performance. If you wish to test an interactive workflow New Relic employs Selenium WebDriverJS to run those test…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now