【发布时间】:2013-12-24 11:47:50
【问题描述】:
我有一个 Java 项目(一个投票系统),我在其中实现了一个 Web 服务。
我的 getResults 方法返回一个 String[]。如果投票完成,则该方法返回填充有“项目 1 - 2 票,项目 2 - 3 票...”的数组。如果不是,则返回带有单个字符串的数组,表示投票仍在进行中。
问题是,如果我从我的 java 应用程序中调用 getResults,它会按预期工作,但如果我从我的 web 服务调用它,它总是返回投票仍在进行,而不是结果。
我正在通过一个 c# 控制台应用程序使用这个 Web 服务,它是 Visual Studio。
我对网络服务很陌生,所以让我问一下。当我像这样实例化我的服务时:
ServerService ss = new ServerService();
它是在我的 Java 应用程序中创建我的类 Server() 的新实例,还是只是连接到我当前实例的一种方式?
我希望我已经很好地解释了我的问题,希望你能帮助我。
谢谢,圣诞快乐 :)
编辑:
这是 Web 服务访问的方法
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();
}
}
}
【问题讨论】:
-
代码行:ServerService ss = new ServerService(); 创建代理类的新对象,该对象是在您添加服务引用时在 Visual Studio 应用程序中创建的.现在这个对象会调用你的 webmethod。你可以发布你的服务的一部分吗?方法不止一种吗?
-
在我的帖子中添加了 webmethod,需要看 wsdl 吗?
-
是的,还有其他一些事情:1. 结束值(我猜这必须与调用者无关) 2. WSDL 3. 调用此服务的 C# 代码。 4.绑定细节等
-
见上面的 wsdl 和 c# 代码。如果投票已经结束(有时间限制),则为真,如果仍在进行,则为假。我认为问题不在 c# 代码中,因为我已经使用 eclipse 集成的 Web 服务工具对其进行了测试,并且发生了同样的事情
标签: c# java .net web-services