gpt4 book ai didi

java - 从 C# 客户端调用带有对象参数的 Java Soap Web 服务方法

转载 作者:行者123 更新时间:2023-12-01 09:19:08 25 4
gpt4 key购买 nike

我想将对象列表作为 Web 服务的输入传递。我发现我们无法使用 SSIS 中内置的 Web 服务任务来实现这一点。所以我尝试通过使用 C# 代码的脚本任务来调用它。我能够通过脚本任务调用 Java Web 服务(SOAP)。我可以通过将字符串等简单参数传递给 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    

最佳答案

错误信息是正确的。该服务需要 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));

关于java - 从 C# 客户端调用带有对象参数的 Java Soap Web 服务方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40285948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com