我想传递Object列表作为Web服务的输入。 我开始知道我们无法使用SSIS中的内置Web服务任务实现这一目标。所以我尝试通过使用C#Code的脚本任务来调用它。 我可以通过脚本Task调用Java Web Service(SOAP)。 我可以通过将简单的参数(如string)传递给Web服务方法来进行测试。 现在我想将对象列表作为参数传递给Web服务方法。 出于测试目的,我首先尝试传递一个对象。 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;
}
}
相应的代理客户端类如下
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;
}
}
}
代理类中的方法在
下面[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]));
}
我在客户端调用方法如下
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);
我收到错误
Argument 1: cannot convert from 'Client.Person' to 'Proxyclass.person' ******\ScriptMain.cs
答案 0 :(得分:1)
错误消息是正确的。该服务需要ProxyClass.person,但您发送的是Client.Person。
而不是这一行:
Person personOne = new Person("Manoj", "123456761", "Administrator", true,testList);
您应该创建一个ProxyClass.person-object并手动映射参数或使用AutoMapper或类似的。
您还需要从
更改序列化XmlSerializer xmlSer = new XmlSerializer(typeof(Person));
到
XmlSerializer xmlSer = new XmlSerializer(typeof(ProxyClass.person));