简体   繁体   English

从C#客户端使用对象参数调用Java Soap Web服务方法

[英]Call a Java Soap Web Service Method with object parameter from C# Client

I want to pass list of Object as the input to the web service. 我想将对象列表作为输入传递到Web服务。 I came to know we cannot achieve this using the built in Web Service task in SSIS. 我知道我们无法使用SSIS中的内置Web服务任务来实现这一目标。 So I tried calling it through script task which uses C# Code. 因此,我尝试通过使用C#代码的脚本任务来调用它。 I am able to call a Java Web Service(SOAP) through script Task. 我可以通过脚本Task调用Java Web Service(SOAP)。 I am able to test by passing simple parameters like string to the web service method. 我可以通过将简单的参数(例如字符串)传递给Web服务方法来进行测试。 Now I want to pass list of objects as parameter to the Web service method. 现在,我想将对象列表作为参数传递给Web服务方法。 For testing purpose first I tried passing a object. 为了进行测试,我首先尝试传递一个对象。 The class in the c# client is as below C#客户端中的类如下

  [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    

The error message is correct. 错误消息是正确的。 The service expects a ProxyClass.person but you are sending a Client.Person. 该服务需要ProxyClass.person,但是您正在发送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. 您应该创建一个ProxyClass.person对象并手动映射参数或使用AutoMapper或类似方法。

You also need to change serialization from 您还需要从

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

to

XmlSerializer xmlSer = new XmlSerializer(typeof(ProxyClass.person));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM