How to query a web service via POST request in Android?

前端 未结 2 1269
半阙折子戏
半阙折子戏 2020-12-02 01:39

I am totally new to Web Feature Service (WFS) but I want to build an Android application with ksoap2-android on top of an API publishing its data via WFS. I would like to re

相关标签:
2条回答
  • 2020-12-02 01:54

    Normally, and from what little experience I have with ksoap2, you would do something like this.

    SoapObject request = new SoapObject("http://www.webserviceX.NET", "GetCitiesByCountry");
    String soapAction = "http://www.webserviceX.NET/GetCitiesByCountry";
    
    request.addProperty("CountryName", "india");
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.bodyOut = request;
    envelope.dotNet = true;
    
    HttpTransport ht = new HttpTransport("http://www.webservicex.net/globalweather.asmx");
    ht.debug = true;
    //System.err.println( ht.requestDump );
    
    ht.call(soapAction,envelope);
    System.out.println("####################: " +envelope.getResponse());
    //SoapObject result = (SoapObject)envelope.getResponse();
    

    So basically you should just take your soapObject and call addProperty() to it.

    0 讨论(0)
  • 2020-12-02 02:00

    @JJD i see you left me a msg in here
    I have a meeting in a while, but i took a look at your question and would be glad to help as much as possible. I see you have a problem reading the schema definition . this ws definition you have is chained one inside the other thats why it confused you reading it:

    If you go on : http://schemas.opengis.net/wfs/1.1.0/wfs.xsd

    take the method "GetCapabilities" and let's read it in the Web service definition:

    PS:I did not test these but:

    • namespace i think should be : http://www.opengis.net/wfs (from targetNamespace)
    • methodName: GetCapabilities
    • url: http://schemas.opengis.net/wfs/1.1.0/wfs.xsd


    Now You have the request of GetCapabilities:

    <!-- REQUEST -->
    <xsd:element name="GetCapabilities" type="wfs:GetCapabilitiesType"/>
    <xsd:complexType name="GetCapabilitiesType">
        <xsd:annotation>
        </xsd:annotation>
        <xsd:complexContent>
        <xsd:extension base="ows:GetCapabilitiesType">
        <xsd:attribute name="service" type="ows:ServiceType" use="optional" default="WFS"/>
        </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
    

    GetCapabilities has a complex type of the type: GetCapabilitiesType, which you find in one of the xsd link on this page, precisely "owsGetCapabilities.xsd"

    --> After opening it ie, : http://schemas.opengis.net/ows/1.0.0/owsGetCapabilities.xsd

    You find this complex type definition:

    <complexType name="GetCapabilitiesType">
    <annotation>
         <documentation>
             XML encoded GetCapabilities operation request. This operation 
             allows clients to retrieve service metadata about a specific service instance.
             In this XML encoding, no "request" parameter is included, since the element name 
             specifies the specific operation. This base type shall be extended by each specific 
             OWS to include the additional required "service" attribute, with the correct value for that OWS. 
         </documentation>
    </annotation>
    <sequence>
         <element name="AcceptVersions" type="ows:AcceptVersionsType" minOccurs="0">
             <annotation>
                 <documentation>When omitted, server shall return latest supported version. 
                 </documentation>
             </annotation>
         </element>
         <element name="Sections" type="ows:SectionsType" minOccurs="0">
             <annotation>
                 <documentation>
                     When omitted or not supported by server, 
                     server shall return complete service metadata (Capabilities) document. 
                 </documentation>
             </annotation>
         </element>
         <element name="AcceptFormats" type="ows:AcceptFormatsType" minOccurs="0">
             <annotation>
                 <documentation>
                     When omitted or not supported by server, server shall return service metadata 
                     document using the MIME type "text/xml". 
                 </documentation>
             </annotation>
         </element>
     </sequence>
    <attribute name="updateSequence" type="ows:UpdateSequenceType" use="optional">
         <annotation>
             <documentation>
                 When omitted or not supported by server, 
                 server shall return latest complete service 
                 metadata document. 
             </documentation>
         </annotation>
    </attribute>
    </complexType>
    

    Now this GetCapabilitiesType has elements /attributes:
    name="AcceptVersions" of type="ows:AcceptVersionsType" and minOccurs="0" ie can be null name="Sections" of type="ows:SectionsType" and minOccurs="0" ie can be null name="AcceptFormats" of type="ows:AcceptFormatsType" and minOccurs="0" ie can be null name="updateSequence" of type="ows:UpdateSequenceType" and its is optional -->use="optional"

    Where to find these attributes definitions?
    -->on this same page you have: AcceptVersionsType is :

    <complexType name="AcceptVersionsType">
     <annotation>
     <documentation>
      Prioritized sequence of one or more specification versions accepted by client, with preferred versions listed first. See Version negotiation subclause for more information.     
     </documentation>
     </annotation>
     <sequence>
      <element name="Version" type="ows:VersionType" maxOccurs="unbounded"/>
     </sequence>
    </complexType>
    


    so AcceptVersionsType has an element of type: VersionType can be found at xsd owsOperationsMetadata.xsd ( which is on the same link of this page) and on it you have xsd:owsCommon.xsd this is this where VersionType is found ie: http://schemas.opengis.net/ows/1.0.0/owsCommon.xsd

    <simpleType name="VersionType">
      <annotation>
        <documentation>Specification version for OWS operation. The string value shall contain one x.y.z "version" value (e.g., "2.1.3"). A version number shall contain three non-negative integers separated by decimal points, in the form "x.y.z". The integers y and z shall not exceed 99. Each version shall be for the Implementation Specification (document) and the associated XML Schemas to which requested operations will conform. An Implementation Specification version normally specifies XML Schemas against which an XML encoded operation response must conform and should be validated. See Version negotiation subclause for more information. </documentation>
      </annotation>
      <restriction base="string"/>
    </simpleType>
    

    and sectionsType is:

    <complexType name="SectionsType">
     <annotation>
       <documentation>
        Unordered list of zero or more names of requested sections in complete service metadata document. Each Section value shall contain an allowed section name as specified by each OWS specification. See Sections parameter subclause for more information.            
       </documentation>
     </annotation>
     <sequence>
        <element name="Section" type="string" minOccurs="0" maxOccurs="unbounded"/>
     </sequence>
    </complexType>
    

    (SectionsType has an element of simple type String)

    And AcceptFormatsType is:

    <complexType name="AcceptFormatsType">
     <annotation>
       <documentation>
        Prioritized sequence of zero or more GetCapabilities operation response formats desired by client, with preferred formats listed first. Each response format shall be identified by its MIME type. See AcceptFormats parameter use subclause for more information. 
       </documentation>
     </annotation>
     <sequence>
      <element name="OutputFormat" type="ows:MimeType" minOccurs="0" maxOccurs="unbounded"/>
      </sequence>
    </complexType>
    

    (AcceptFormatsType has an element of type MimeType which is found same place as VersionType ie : http://schemas.opengis.net/ows/1.0.0/owsCommon.xsd

    <simpleType name="MimeType">
      <annotation>
        <documentation>XML encoded identifier of a standard MIME type, possibly a parameterized MIME type. </documentation>
      </annotation>
      <restriction base="string">
        <pattern value="(application|audio|image|text|video|message|multipart|model)/.+(;s*.+=.+)*"/>
      </restriction>
    </simpleType>
    

    and UpdateSequenceType is( it is a simple type not complex type):

     <simpleType name="UpdateSequenceType">
     <annotation>
      <documentation>
       Service metadata document version, having values that are "increased" whenever any change is made in service metadata document. Values are selected by each server, and are always opaque to clients. See updateSequence parameter use subclause for more information.     
       </documentation>
      </annotation>
     <restriction base="string"/>
     </simpleType>
    

    (UpdateSequenceType is a simple type)

    Now i hope it got clearer how to read the schema . Now complex type means object unlike simple type (ex: int). When you have complex types, and you are using ksoap2, you have to create local representations in classes (objects) that implements kvmSerializable ( a ksoap2 serialization interface).

    Now , you can read my answers to know how to do that on : Link1,link2,link3. I wrote some details which will help you understand how to start coding.

    I won't be on my pc for the day. Hope this helps,let me know if anything of wt i said is ambigous.

    0 讨论(0)
提交回复
热议问题