Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need help in consuming web Service method

Posted on 2009-03-29
6
Medium Priority
?
434 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 80 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

971 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