Solved

Need help in consuming web Service method

Posted on 2009-03-29
6
426 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Threat Trends for MSPs to Watch

See the findings.
Despite its humble beginnings, phishing has come a long way since those first crudely constructed emails. Today, phishing sites can appear and disappear in the length of a coffee break, and it takes more than a little know-how to keep your clients secure.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Trigger C# code inside the SQL Server 6 57
Load XML element 3 43
exchange 2013 10 36
web api controller with multiple posts that accept different objects 1 25
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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