0

I want to pass list of Object as the input to the web service. I came to know we cannot achieve this using the built in Web Service task in SSIS. So I tried calling it through script task which uses C# Code. I am able to call a Java Web Service(SOAP) through script Task. I am able to test by passing simple parameters like string to the web service method. Now I want to pass list of objects as parameter to the Web service method. For testing purpose first I tried passing a object. The class in the c# client is as below

  [Serializable]
        public class Person
        {
            public string _PersonName;
            public string _PersonNumber;
            public string _Password;
            public bool _isTrue;
            public List<string> _configs;
            public Person()
            {
            }

            public Person(string PersonName, string PersonNumber, string Password, bool val)
            {
                _PersonName = PersonName;
                _PersonNumber = PersonNumber;
                _Password = Password;
                _isTrue = val;
                // _configs = config;        
            }
        }

The corresponding proxy client class is as below

public partial class person {

        private string _PersonNameField;

        private string _PersonNumberField;

        private string _PasswordField;

        private bool _isTrueField;

        private string[] _configsField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string _PersonName {
            get {
                return this._PersonNameField;
            }
            set {
                this._PersonNameField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string _PersonNumber {
            get {
                return this._PersonNumberField;
            }
            set {
                this._PersonNumberField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string _Password {
            get {
                return this._PasswordField;
            }
            set {
                this._PasswordField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public bool _isTrue {
            get {
                return this._isTrueField;
            }
            set {
                this._isTrueField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("_configs", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=true)]
        public string[] _configs {
            get {
                return this._configsField;
            }
            set {
                this._configsField = value;
            }
        }
    }

The method in the proxy class is below

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestNamespace="http://sample.xyz.abc.ext/", ResponseNamespace="http://sample.xyz.abc.ext/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        [return: System.Xml.Serialization.XmlElementAttribute("return", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string createPerson([System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] person arg0) {
            object[] results = this.Invoke("createJigBoard", new object[] {
                        arg0});
            return ((string)(results[0]));
        }

I am calling the method in the client as below

ServiceReference.TestService per = new ServiceReference.TestService();
 var testList=new List<string>();
 Person personOne = new Person("Manoj", "123456761", "Administrator", true,testList);
            NetworkCredential myCred = new NetworkCredential("person", "person");
            CredentialCache myCache = new CredentialCache();
            myCache.Add(new Uri("http://pcblr********:80/*******/servlet/TestService"), "Basic", myCred);            
            StringWriter textWriter = new StringWriter();
            XmlSerializer xmlSer = new XmlSerializer(typeof(Person));          
            xmlSer.Serialize(textWriter, personOne);
                       textWriter.Close();
            per.createPerson(personOne);

I am getting the error

Argument 1: cannot convert from 'Client.Person' to 'Proxyclass.person'  ******\ScriptMain.cs    

1 Answer 1

1

The error message is correct. The service expects a ProxyClass.person but you are sending a Client.Person.

Instead of this line:

Person personOne = new Person("Manoj", "123456761", "Administrator", true,testList);

you should create a ProxyClass.person-object and map the parameters manually or use AutoMapper or similar.

You also need to change serialization from

XmlSerializer xmlSer = new XmlSerializer(typeof(Person));

to

XmlSerializer xmlSer = new XmlSerializer(typeof(ProxyClass.person));
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Now I am able to pass single object .. I want to pass list<object> but it is treating as object array. I changed the settings as below stackoverflow.com/questions/24621993/…
Web service automatically will take care of serializing. List.ToArray() works fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.