Android Studio,Ksoap2 http请求失败,http状态:404

时间:2017-11-03 15:56:07

标签: android web-services http-status-code-404 ksoap2 webservice-client

你好我检查过&重新检查我的KSoap2参数:命名空间,方法,SoapAction和URL。一切看起来都不错,但我总是得到错误404

我创建的WFC服务基于Microsoft的示例: https://docs.microsoft.com/en-us/dotnet/framework/wcf/getting-started-tutorial

使用示例C#Client成功调用WFC服务,从浏览器打开以获取xml信息成功,同样使用WFC Test Client也成功。

为此,我已经打开/输出端口8000。在网上提供了一些提示后,我还在主机中将WSHttpBinding更改为BasicHttpBinding。但是当我尝试使用KSoap2 ver3.6.2从Android Studio 3.0调用时,它总是得到404

下面的

是我从浏览器中复制的xml数据:

This XML file does not appear to have any style information associated 
with it. The document tree is shown below.
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-
wssecurity-utility-1.0.xsd" 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
xmlns:tns="http://tempuri.org/" 
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" 
xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" 
xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" 
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" 
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" 
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" 
xmlns:wsa10="http://www.w3.org/2005/08/addressing" 
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" 
name="CalculatorService" targetNamespace="http://tempuri.org/">
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://localhost:8000/WCFTRIAL?xsd=xsd0" 
namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://localhost:8000/WCFTRIAL?xsd=xsd1" 
namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="ICalculator_Add_InputMessage">
<wsdl:part name="parameters" element="tns:Add"/>
</wsdl:message>
<wsdl:message name="ICalculator_Add_OutputMessage">
<wsdl:part name="parameters" element="tns:AddResponse"/>
</wsdl:message>
<wsdl:message name="ICalculator_Subtract_InputMessage">
<wsdl:part name="parameters" element="tns:Subtract"/>
</wsdl:message>
<wsdl:message name="ICalculator_Subtract_OutputMessage">
<wsdl:part name="parameters" element="tns:SubtractResponse"/>
</wsdl:message>
<wsdl:message name="ICalculator_Multiply_InputMessage">
<wsdl:part name="parameters" element="tns:Multiply"/>
</wsdl:message>
<wsdl:message name="ICalculator_Multiply_OutputMessage">
<wsdl:part name="parameters" element="tns:MultiplyResponse"/>
</wsdl:message>
<wsdl:message name="ICalculator_Divide_InputMessage">
<wsdl:part name="parameters" element="tns:Divide"/>
</wsdl:message>
<wsdl:message name="ICalculator_Divide_OutputMessage">
<wsdl:part name="parameters" element="tns:DivideResponse"/>
</wsdl:message>
<wsdl:message name="ICalculator_GetJunkData_InputMessage">
<wsdl:part name="parameters" element="tns:GetJunkData"/>
</wsdl:message>
<wsdl:message name="ICalculator_GetJunkData_OutputMessage">
<wsdl:part name="parameters" element="tns:GetJunkDataResponse"/>
</wsdl:message>
<wsdl:portType name="ICalculator">
<wsdl:operation name="Add">
<wsdl:input wsaw:Action="http://tempuri.org/ICalculator/Add"
 message="tns:ICalculator_Add_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ICalculator/AddResponse" 
message="tns:ICalculator_Add_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="Subtract">
<wsdl:input wsaw:Action="http://tempuri.org/ICalculator/Subtract"
message="tns:ICalculator_Subtract_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ICalculator/SubtractResponse" 
message="tns:ICalculator_Subtract_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="Multiply">
<wsdl:input wsaw:Action="http://tempuri.org/ICalculator/Multiply" 
message="tns:ICalculator_Multiply_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ICalculator/MultiplyResponse" 
message="tns:ICalculator_Multiply_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="Divide">
<wsdl:input wsaw:Action="http://tempuri.org/ICalculator/Divide"  
message="tns:ICalculator_Divide_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ICalculator/DivideResponse"  
message="tns:ICalculator_Divide_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="GetJunkData">
<wsdl:input wsaw:Action="http://tempuri.org/ICalculator/GetJunkData" 
message="tns:ICalculator_GetJunkData_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ICalculator/GetJunkDataResponse" 
message="tns:ICalculator_GetJunkData_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_ICalculator" type="tns:ICalculator">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Add">
<soap:operation soapAction="http://tempuri.org/ICalculator/Add" 
style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="Subtract">
<soap:operation soapAction="http://tempuri.org/ICalculator/Subtract" 
style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="Multiply">
<soap:operation soapAction="http://tempuri.org/ICalculator/Multiply" 
style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="Divide">
<soap:operation soapAction="http://tempuri.org/ICalculator/Divide" 
style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetJunkData">
<soap:operation soapAction="http://tempuri.org/ICalculator/GetJunkData" 
style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CalculatorService">
<wsdl:port name="BasicHttpBinding_ICalculator" 
binding="tns:BasicHttpBinding_ICalculator">
<soap:address location="http://localhost:8000/WCFTRIAL/CalculatorService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

这是我在Android Studio中的代码:

private class Soapcall extends AsyncTask<String,Object,String>{

    public static final String NAMESPACE ="http://tempuri.org/";
    public static final String METHOD_NAME ="GetJunkData";
    public static final String SOAPACTION = 
         "http://tempuri.org/ICalculator/GetJunkData";
    public static final String URI =
         "http://192.168.1.201:8000/WCFTRIAL?wsdl";
    public static final int Timeout=3000;
    String response;

    @Override
    protected String doInBackground(String... strings) {
        SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
        SoapSerializationEnvelope envelope = new 
            SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet=true;
        envelope.setOutputSoapObject(request);
        HttpTransportSE transport = new HttpTransportSE(URI,Timeout);

        try{
            transport.call(SOAPACTION,envelope); //<--ERROR OCCUR HERE
            response = (String)envelope.getResponse();
        }catch (Exception e){
            e.printStackTrace();
            Log.e("Error",e.getMessage().toString());
        }
        return response;
    }

摘要:

NAMESPACE ="http://tempuri.org/";
METHOD_NAME ="GetJunkData";
SOAPACTION = "http://tempuri.org/ICalculator/GetJunkData";
URL ="http://192.168.1.201:8000/WCFTRIAL?wsdl"; 

我很确定基于WDSL这是正确的,请赐教我如何纠正这个404错误。

0 个答案:

没有答案