[英]Consuming java web service through .net - data inconsistence
我有一个Java项目(投票系统),在其中实现了Web服务。
我的getResults方法返回一个String []。 如果完成投票,则该方法返回填充有“项目1-2票,项目2-3投票...”的数组。 如果不是,则返回带有单个字符串的数组,表示仍在进行投票。
问题是,如果我从java应用程序中调用getResults,它将按预期工作,但如果我从Web服务中调用它,则始终返回表决仍在进行,而永远不会返回结果。
我通过ac#控制台应用程序使用了这个Web服务,即Visual Studio。
我对Web服务还很陌生,所以让我问这个。 当我这样实例化服务时:
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();
}
}
}
它仅实例化服务的C#代理-.NET自动生成的类,具有所有幕后代码来管理与服务的通信。
我建议您先尝试使用SoapUI之类的工具测试服务,然后再尝试将其与.NET集成,看看是否存在相同的问题。
我无法在您的代码中找出确切的问题,但是这里有一些指针可以帮助您解决问题。
<wsdl:operation name="getResults"> <wsdl:input message="impl:getResultsRequest" name="getResultsRequest"> </wsdl:input> <wsdl:output message="impl:getResultsResponse" name="getResultsResponse"> </wsdl:output> </wsdl:operation>
但是您期望在C#代码中将字符串作为输出。
2。 您需要在C#端创建两个对象:getResultsRequest和getResultsResponse
我知道您通过Eclipse遇到了同样的错误,但是由于从Java客户端调用它时,您的服务运行良好。 因此,您的服务逻辑是正确的。 现在,唯一可能发生问题的地方就是您的服务与客户端之间的通信。
因此,我建议的C#代码为:
namespace WSTest
{
class Program
{
static void Main(string[] args)
{
ServerService ss = new ServerService();
getResultRequest request = new getResultRequest();
getResultResponse response = new getResultResponse();
response = ss.getResultResponse(request);
// Do something with response.
Console.ReadLine();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.