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

标签 c# soap asmx axis

我有一个由 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/

相关文章:

java - Spring 配置文件配置

asp.net - Web服务-executiontimeout和sendtimeout-receivetimeout-closetimeout和opentimeout区别?

c# - 登录控制台应用程序(带有 DI 的 .NET Core)

c# - 如何在 Entity Framework 4 中获取 SQL 2008 的下一个主键

c# - 如何在 Windows 中使用 C#、WPF 创建一个 "push notification"服务?

json - ASP.NET Core .NET 6 应用程序默认返回 XML 而不是 JSON

c# - 使用 RAW SOAP XML 提交 SOAP Web 服务请求

c# - TPL 数据流工作流

java - 使用 CXF 服务 (ssl .net) 时连接重置

asp.net - 确定 HTTP 请求是否是 HttpApplication.AuthenticateRequest 上的 SOAP 请求