I developed a webservice in .net and I'm trying to call it in Android. To call the webservice I'm using ksoap2.

我在.net中开发了一个web服务,我试图在Android中调用它。要调用web服务我正在使用kso​​ap2。

The WDSL's URL is: http://localhost/Cidadaos_Cidade/Open.asmx?WSDL

WDSL的URL是:http://localhost/Cidadaos_Cidade/Open.asmx?WSDL

Here's the WSDL

这是WSDL

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://Cidadaos_Cidade/Open/" xmlns:s0="http://www.outsystems.com" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://Cidadaos_Cidade/Open/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://www.outsystems.com">
      <s:element name="GetCategoriasFull">
        <s:complexType />
      </s:element>
      <s:element name="GetCategoriasFullResponse">
        <s:complexType>
          <s:sequence>

            <s:element minOccurs="0" maxOccurs="1" name="Out1" type="s0:ArrayOfWORCCategoriaSubcategoriaRecord" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:complexType name="ArrayOfWORCCategoriaSubcategoriaRecord">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="unbounded" name="WORCCategoriaSubcategoriaRecord" nillable="true" type="s0:WORCCategoriaSubcategoriaRecord" />
        </s:sequence>
      </s:complexType>

      <s:complexType name="WORCCategoriaSubcategoriaRecord">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="1" name="ssENCategoria" type="s0:Categoria" />
          <s:element minOccurs="0" maxOccurs="1" name="ssENSubcategoria" type="s0:Subcategoria" />
        </s:sequence>
      </s:complexType>
      <s:complexType name="Categoria">
        <s:sequence>
          <s:element minOccurs="1" maxOccurs="1" name="Id" type="s:int" />

          <s:element minOccurs="0" maxOccurs="1" name="Nome" type="s:string" />
        </s:sequence>
      </s:complexType>
      <s:complexType name="Subcategoria">
        <s:sequence>
          <s:element minOccurs="1" maxOccurs="1" name="Id" type="s:int" />
          <s:element minOccurs="0" maxOccurs="1" name="Nome" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="Imagem" type="s:string" />
          <s:element minOccurs="1" maxOccurs="1" name="CategoriaId" type="s:int" />

        </s:sequence>
      </s:complexType>
      <s:element name="GetCategorias">
        <s:complexType />
      </s:element>
      <s:element name="GetCategoriasResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="Out1" type="s0:ArrayOfCategoria" />

          </s:sequence>
        </s:complexType>
      </s:element>
      <s:complexType name="ArrayOfCategoria">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="unbounded" name="Categoria" nillable="true" type="s0:Categoria" />
        </s:sequence>
      </s:complexType>
    </s:schema>

  </wsdl:types>
  <wsdl:message name="GetCategoriasFullSoapIn">
    <wsdl:part name="parameters" element="s0:GetCategoriasFull" />
  </wsdl:message>
  <wsdl:message name="GetCategoriasFullSoapOut">
    <wsdl:part name="parameters" element="s0:GetCategoriasFullResponse" />
  </wsdl:message>
  <wsdl:message name="GetCategoriasSoapIn">
    <wsdl:part name="parameters" element="s0:GetCategorias" />

  </wsdl:message>
  <wsdl:message name="GetCategoriasSoapOut">
    <wsdl:part name="parameters" element="s0:GetCategoriasResponse" />
  </wsdl:message>
  <wsdl:portType name="OpenSoap">
    <wsdl:operation name="GetCategoriasFull">
      <wsdl:input message="tns:GetCategoriasFullSoapIn" />
      <wsdl:output message="tns:GetCategoriasFullSoapOut" />
    </wsdl:operation>

    <wsdl:operation name="GetCategorias">
      <wsdl:input message="tns:GetCategoriasSoapIn" />
      <wsdl:output message="tns:GetCategoriasSoapOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="OpenSoap" type="tns:OpenSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="GetCategoriasFull">
      <soap:operation soapAction="http://Cidadaos_Cidade/Open/GetCategoriasFull" style="document" />

      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetCategorias">
      <soap:operation soapAction="http://Cidadaos_Cidade/Open/GetCategorias" style="document" />

      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="OpenSoap12" type="tns:OpenSoap">

    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="GetCategoriasFull">
      <soap12:operation soapAction="http://Cidadaos_Cidade/Open/GetCategoriasFull" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>

    </wsdl:operation>
    <wsdl:operation name="GetCategorias">
      <soap12:operation soapAction="http://Cidadaos_Cidade/Open/GetCategorias" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>

    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="Open">
    <wsdl:port name="OpenSoap" binding="tns:OpenSoap">
      <soap:address location="http://localhost/Cidadaos_Cidade/Open.asmx" />
    </wsdl:port>
    <wsdl:port name="OpenSoap12" binding="tns:OpenSoap12">
      <soap12:address location="http://localhost/Cidadaos_Cidade/Open.asmx" />
    </wsdl:port>

  </wsdl:service>
</wsdl:definitions>

And here's the code to call it

这是调用它的代码

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);


        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        //soapEnvelope.dotNet = true; //tried with and without this flag
        soapEnvelope.setOutputSoapObject(request);

        AndroidHttpTransport aht = new AndroidHttpTransport(URL);
        try{
            //crashes in the following line with the exception:
            //java.net.ConnectException: localhost/127.0.0.1:80 - Connection refused
            aht.call(SOAP_ACTION, soapEnvelope);
            SoapObject resultsRequestSOAP = (SoapObject) soapEnvelope.bodyIn;

        }catch(Exception ex){
            ex.printStackTrace();
        }

Can anyone help me? I already tried invoking it using a C#.net project and works perfectly. Sorry to put all the XML and code here but I'm desperate...

谁能帮我?我已经尝试使用C#.net项目调用它并且工作得很好。很抱歉把所有的XML和代码放在这里,但我很绝望......

3 个解决方案

#1


8

i dont know much about android development but localhost is a loopback adress to your android device. you need to replace localhost with the name or ip-address of the server that is running your webservice.

我不太了解Android开发,但localhost是你的Android设备的环回地址。您需要将localhost替换为运行Web服务的服务器的名称或IP地址。

更多相关文章

  1. Java Android套接字连接。错误的IP地址导致应用程序停止响应
  2. Android代码性能优化技巧
  3. Android公钥私钥及代码详细解读
  4. Android利用IP地址定位城市(全世界可用)
  5. android OSChina 客户端源代码剖析
  6. android代码混淆 GSON完满解决
  7. Android开源代码解读の地图照片应用Panoramio的实现详解(六)
  8. 在app引擎端点的启动时执行代码
  9. Android获取WIFI状态下的IP地址以及MAC地址

随机推荐

  1. Spring入门这一篇就够了
  2. Spring【依赖注入】就是这么简单
  3. 面试官:知道ThreadLocal嘛?谈谈你对它的理
  4. Spring【AOP模块】就这么简单
  5. Springboot整合redis(Lettuce版本)
  6. Spring【DAO模块】知识要点
  7. 阿里的OceanBase数据库世界第一,底层原来
  8. Springboot整合Websocket实现后端向前端
  9. MyBatis之Mapper XML 文件详解(六)-缓存
  10. MyBatis之Mapper XML 文件详解(四)-JDBC