WCF主机和Android客户端,Ksoap2 http请求失败,http状态:404 [英] WCF host and Android Client, Ksoap2 http request failed, http status : 404

查看:87
本文介绍了WCF主机和Android客户端,Ksoap2 http请求失败,http状态:404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


你好我检查&重新检查我的KSoap2参数:Namespace,Method,SoapAction和URL everythings看起来没问题,但我总是得到错误404



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



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



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



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

此XML文件似乎没有任何关联的样式信息$ b文件树如下所示。
< 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 = QUOT; 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 = QUOT; 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"元素= QUOT; TNS:新增] />
< / wsdl:message>
< wsdl:message name =" ICalculator_Add_OutputMessage">
< wsdl:part name =" parameters"元素= QUOT; TNS:AddResponse" />
< / wsdl:message>
< wsdl:message name =" ICalculator_Subtract_InputMessage">
< wsdl:part name =" parameters"元素= QUOT; TNS:减去" />
< / wsdl:message>
< wsdl:message name =" ICalculator_Subtract_OutputMessage">
< wsdl:part name =" parameters"元素= QUOT; TNS:SubtractResponse" />
< / wsdl:message>
< wsdl:message name =" ICalculator_Multiply_InputMessage">
< wsdl:part name =" parameters"元素= QUOT; TNS:正片" />
< / wsdl:message>
< wsdl:message name =" ICalculator_Multiply_OutputMessage">
< wsdl:part name =" parameters"元素= QUOT; TNS:MultiplyResponse" />
< / wsdl:message>
< wsdl:message name =" ICalculator_Divide_InputMessage">
< wsdl:part name =" parameters"元素= QUOT; TNS:分割和QUOT; />
< / wsdl:message>
< wsdl:message name =" ICalculator_Divide_OutputMessage">
< wsdl:part name =" parameters"元素= QUOT; TNS:DivideResponse" />
< / wsdl:message>
< wsdl:message name =" ICalculator_GetJunkData_InputMessage">
< wsdl:part name =" parameters"元素= QUOT; TNS:GetJunkData" />
< / wsdl:message>
< wsdl:message name =" ICalculator_GetJunkData_OutputMessage">
< wsdl:part name =" parameters"元素= QUOT; 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"类型= QUOT; 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中的代码:



私有类Soapcall扩展了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;
字符串响应;

@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(例外e){
e.printStackTrace();
Log.e(" Error",e.getMessage()。toString());
}
返回回复;
}





总结我的

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



我很确定这是基于WSDL的正确,请点亮我如何纠正这个404错误。









0 下来
投票
收藏夹

解决方案

我建议您使用Fiddler并在获得404时查看原始HTML流量。


https://www.telerik.com/videos/fiddler


Hi Im had check & recheck my KSoap2 param : Namespace, Method, SoapAction, and URL everythings looks ok but I always got error 404

The WFC service I create based on microsoft examples: https://docs.microsoft.com/en-us/dotnet/framework/wcf/getting-started-tutorial

Using the examples C# Client was success to call the WFC services, opening from browser to get xml info was success, also using WFC Test Client also success.

I already open tcp in/out port 8000 for this. Following some hints on the web Im also had change WSHttpBinding into BasicHttpBinding in my host. But when I tried to call from Android Studio 3.0 using KSoap2 ver3.6.2 its always got 404

below is the xml data I copied from browse :

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>


and this is my code in 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;
    }


To summary my

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

Im pretty sure this is correct based on the WSDL, please en-light me how Im to correct this 404 error.

0down votefavorite

解决方案

I suggest that you use Fiddler and look at the raw HTML traffic when you get the 404.

https://www.telerik.com/videos/fiddler


这篇关于WCF主机和Android客户端,Ksoap2 http请求失败,http状态:404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆