gpt4 book ai didi

c# - Apache Axis 客户端、ASMX 服务、阵列不兼容问题

转载 作者:行者123 更新时间:2023-11-30 16:52:23 26 4
gpt4 key购买 nike

我有一个由 Apache Axis 客户端调用的 .Net Web 服务。他们在我们的服务上调用了一个名为 getBulkBalance 的方法,该方法为活跃玩家获取游戏中玩家的余额,例如滚动代码等。该调用适用于单个玩家请求,但是不适用于多个请求,这使得 getBulkBalance 非常……无用,因为还有一个 getBalance 方法。

因为有多个节点,如下图:

  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:GetBulkBalanceRequest>
<!--Optional:-->
<tem:secureLogin>login</tem:secureLogin>
<!--Optional:-->
<tem:securePassword>password</tem:securePassword>
<!--Zero or more repetitions:-->
<tem:playerIDList>60</tem:playerIDList>
<tem:playerIDList>61</tem:playerIDList>
</tem:GetBulkBalanceRequest>
</soapenv:Body>
</soapenv:Envelope>

如果他们只调用一个,它工作正常。如果他们在一个节点中传入 60,61,它就可以正常工作。另一方不会/不能改变他们的客户端处理 Int64 数组的方式。

我的方法是这样的:

    [WebMethod]
[SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare, Action = "GetBulkBalance")]
[return: XmlElement(ElementName = "GetBulkBalanceResponse")]
public GetBulkBalanceResponse GetBulkBalance(GetBulkBalanceRequest GetBulkBalanceRequest)

GetBulkBalanceRequest如下:

[Serializable]
public class GetBulkBalanceRequest
{
[XmlElement(Namespace = Constants.ServiceNamespace)]
public string secureLogin;
[XmlElement(Namespace = Constants.ServiceNamespace)]
public string securePassword;
[XmlElement(Namespace = Constants.ServiceNamespace)]
public Int64[] playerIDList;
}

关于如何让 Axis 和 WCF 更好地发挥作用有什么想法吗?也许我缺少某些属性?提前致谢!

最佳答案

德里克,

如果客户端无需更改任何内容,您可以将列表声明为字符串并在服务器代码中进行解析吗?

[Serializable]
public class GetBulkBalanceRequest
{
// ....
[XmlElement(Namespace = Constants.ServiceNamespace)]
public String playerIDList;
}

您的服务器代码将是:

[WebService(Namespace = Constants.ServiceNamespace)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
[SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare, Action = "GetBulkBalance")]
[return: XmlElement(ElementName = "GetBulkBalanceResponse")]
public GetBulkBalanceResponse GetBulkBalance(GetBulkBalanceRequest getBulkBalanceRequest)
{
Int64 [] ids = getBulkBalanceRequest.playerIDList
.Split(',')
.Select(s => Int64.Parse(s)).ToArray();
return new GetBulkBalanceResponse { responseValue = "response42" };
}
}

据我所知,您正在编写 ASMX 服务,而不是“真正的”WCF 服务。使用 WCF,您可以在消息检查器中解析消息的主体:

  1. 当然是客户端的 IClientMessageInspector
  2. 服务器端的IDispatcherMessageInspector

希望对你有帮助

关于c# - Apache Axis 客户端、ASMX 服务、阵列不兼容问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32657408/

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