我试图通过Android Eclipse Emulator调用在本地Tomcat服务器上运行的WSDL Web服务。我正在使用KSOAP2发起服务呼叫。
我在尝试获得回复时看到的错误:
SoapFault - faultcode: 'S:Client' faultstring: 'Cannot find dispatch method for {http://localhost:8080/test/}getAllAvailableAssessments' faultactor: 'null' detail: null
有些注意事项:
这是调用webservice的类:
private static String NAMESPACE = "http://localhost:8080/test/";
private static String URL = "http://10.10.10.55:8080/testwebservices/WebServices/AssessmentListingService?wsdl";
private static String METHOD_NAME = "getAllAvailableAssessments";
private static String SOAP_ACTION = "http://localhost:8080/test/getAllAvailableAssessments";
public static String getAllAvailableAssessments()
{
String webServiceResult = "";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
webServiceResult = response.toString();
}
catch(Exception e)
{
e.printStackTrace();
}
return webServiceResult;
}
这是wsdl文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:assessmentListing="http://localhost:8080/test/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="AssessmentListingService" targetNamespace="http://localhost:8080/test/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://localhost:8080/test/AssessmentListing/">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://localhost:8080/test/AssessmentListing/" schemaLocation="AssessmentListing.xsd"></xsd:import>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getAllAvailableAssessmentsRequest">
<wsdl:part name="parameters"
element="xsd:getAllAvailableAssessmentsRequest">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getAllAvailableAssessmentsResponse">
<wsdl:part name="parameters"
element="xsd:getAllAvailableAssessmentsResponse">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="AssessmentListingService">
<wsdl:operation name="getAllAvailableAssessments">
<wsdl:input message="assessmentListing:getAllAvailableAssessmentsRequest"></wsdl:input>
<wsdl:output message="assessmentListing:getAllAvailableAssessmentsResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="AssessmentListingServicePortBinding"
type="assessmentListing:AssessmentListingService">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getAllAvailableAssessments">
<soap:operation
soapAction="http://localhost:8080/test/AssessmentListingService/getAllAvailableAssessments" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="AssessmentListingService">
<wsdl:port name="AssessmentListingServicePort" binding="assessmentListing:AssessmentListingServicePortBinding">
<soap:address location="http://localhost:8080/testwebservices/WebServices/AssessmentListingService" />
</wsdl:port>
</wsdl:service>
任何想法都会受到赞赏。
答案 0 :(得分:0)
SOAP_ACTION
变量不必遵循NAMESPACE + METHOD_NAME
模式。这些值可以是任何值,具体取决于WSDL结构。
将来自SoapUI的请求XML与来自KSOAP2的转储请求XML进行比较后,我看到了不匹配。
特别是在这种情况下,添加&#34;请求&#34; SOAP_ACTION
变量末尾的字符串解决了问题。
因此,
private static String NAMESPACE = "http://localhost:8080/test/";
private static String URL = "http://10.10.10.55:8080/testwebservices/WebServices/AssessmentListingService?wsdl";
private static String METHOD_NAME = "getAllAvailableAssessments";
private static String SOAP_ACTION = "http://localhost:8080/test/getAllAvailableAssessmentsRequest";