我有一个 Java 项目(投票系统),我在其中实现了一个 Web 服务。
我的 getResults 方法返回一个 String[]。如果投票完成,该方法将返回填充有“项目 1 - 2 票,项目 2 - 3 票...”的数组。如果不是,它会返回带有单个字符串的数组,表示投票仍在进行中。
问题是,如果我从 java 应用程序中调用 getResults,它会按预期工作,但如果我从 web 服务中调用它,它总是返回投票仍在进行中,而不是结果。
我通过 Visual Studio 的 C# 控制台应用程序使用此 Web 服务。
我对网络服务还很陌生,所以让我问一下这个问题。当我像这样实例化我的服务时:
ServerService ss = new ServerService();
它是在我的 Java 应用程序中创建我的类 Server()
的新实例还是只是连接到我当前实例的一种方式?
好吧,我希望我已经很好地解释了我的问题,并希望你能帮助我。
谢谢,圣诞快乐:)
编辑:
这是网络服务访问的方法
public String[] getResults() throws RemoteException {
if (ended) {
return results.toArray(new String[results.size()]);
} else {
ArrayList<String> temp = new ArrayList<String>();
temp.add("Voting is still on");
return temp.toArray(new String[temp.size()]);
}
}
编辑2:
WSDL:
<wsdl:definitions targetNamespace="http://backend.ve"
xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://backend.ve" xmlns:intf="http://backend.ve" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema elementFormDefault="qualified" targetNamespace="http://backend.ve" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="getResults">
<complexType/>
</element>
<element name="getResultsResponse">
<complexType>
<sequence>
<element maxOccurs="unbounded" name="getResultsReturn" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="getResultsRequest">
<wsdl:part element="impl:getResults" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getResultsResponse">
<wsdl:part element="impl:getResultsResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="Server">
<wsdl:operation name="getResults">
<wsdl:input message="impl:getResultsRequest" name="getResultsRequest">
</wsdl:input>
<wsdl:output message="impl:getResultsResponse" name="getResultsResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ServerSoapBinding" type="impl:Server">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getResults">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getResultsRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getResultsResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ServerService">
<wsdl:port binding="impl:ServerSoapBinding" name="Server">
<wsdlsoap:address location="http://localhost:8080/VE/services/Server"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
C#:
namespace WSTest
{
class Program
{
static void Main(string[] args)
{
ServerService ss = new ServerService();
foreach (String s in ss.getResults())
{
Console.WriteLine(s);
}
Console.ReadLine();
}
}
}
最佳答案
它只会为您的服务实例化一个 C# 代理 - 由 .NET 自动生成的类,其中包含所有幕后代码来管理与您的服务的通信。
我建议您在尝试将服务与 .NET 集成之前使用 SoapUI 之类的工具测试您的服务,看看是否有同样的问题。
关于c# - 通过.net使用java web服务-数据不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20760359/