Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need help in consuming web Service method

Posted on 2009-03-29
6
Medium Priority
?
430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

704 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