Hi, there,

    When I try using the non-blocking mode to access the webservice of
googlesearch, I always get the AxisFault: The prefix "xsi" for attribute
"xsi:type" associated with an element type "key" is not bound.

    Did you meet this fault before?

    I attached the test code and wsdl file. Any comments would help me a
lot.

--
Regards
Tony
<?xml version="1.0"?>

<!-- WSDL description of the Google Web APIs.
     The Google Web APIs are in beta release. All interfaces are subject to
     change as we refine and extend our APIs. Please see the terms of use
     for more information. -->

<!-- Revision 2002-08-16 -->

<definitions name="GoogleSearch"
             targetNamespace="urn:GoogleSearch"
             xmlns:typens="urn:GoogleSearch"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema";
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/";
             xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/";
             xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";
             xmlns="http://schemas.xmlsoap.org/wsdl/";>

  <!-- Types for search - result elements, directory categories -->

  <types>
    <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"; 
                targetNamespace="urn:GoogleSearch">
            
      <xsd:complexType name="GoogleSearchResult">
        <xsd:all>
          <xsd:element name="documentFiltering"           type="xsd:boolean"/>
          <xsd:element name="searchComments"              type="xsd:string"/>
          <xsd:element name="estimatedTotalResultsCount"  type="xsd:int"/>
          <xsd:element name="estimateIsExact"             type="xsd:boolean"/>
          <xsd:element name="resultElements"              type="typens:ResultElementArray"/>
          <xsd:element name="searchQuery"                 type="xsd:string"/>
          <xsd:element name="startIndex"                  type="xsd:int"/>
          <xsd:element name="endIndex"                    type="xsd:int"/>
          <xsd:element name="searchTips"                  type="xsd:string"/>
          <xsd:element name="directoryCategories"         type="typens:DirectoryCategoryArray"/>
          <xsd:element name="searchTime"                  type="xsd:double"/>
        </xsd:all>
      </xsd:complexType>

      <xsd:complexType name="ResultElement">
        <xsd:all>
          <xsd:element name="summary" type="xsd:string"/>
          <xsd:element name="URL" type="xsd:string"/>
          <xsd:element name="snippet" type="xsd:string"/>
          <xsd:element name="title" type="xsd:string"/>
          <xsd:element name="cachedSize" type="xsd:string"/>
          <xsd:element name="relatedInformationPresent" type="xsd:boolean"/>
          <xsd:element name="hostName" type="xsd:string"/>
          <xsd:element name="directoryCategory" type="typens:DirectoryCategory"/>
          <xsd:element name="directoryTitle" type="xsd:string"/>
        </xsd:all>
      </xsd:complexType>
  
      <xsd:complexType name="ResultElementArray">
        <xsd:complexContent>
          <xsd:restriction base="soapenc:Array">
             <xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="typens:ResultElement[]"/>
          </xsd:restriction>
        </xsd:complexContent>
      </xsd:complexType>

      <xsd:complexType name="DirectoryCategoryArray">
        <xsd:complexContent>
          <xsd:restriction base="soapenc:Array">
             <xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="typens:DirectoryCategory[]"/>
          </xsd:restriction>
        </xsd:complexContent>
      </xsd:complexType>

      <xsd:complexType name="DirectoryCategory">
        <xsd:all>
          <xsd:element name="fullViewableName" type="xsd:string"/>
          <xsd:element name="specialEncoding" type="xsd:string"/>
        </xsd:all>
      </xsd:complexType>

    </xsd:schema>
  </types> 

  <!-- Messages for Google Web APIs - cached page, search, spelling. -->
             
  <message name="doGetCachedPage">
    <part name="key"            type="xsd:string"/>
    <part name="url"            type="xsd:string"/>
  </message>

  <message name="doGetCachedPageResponse">
    <part name="return"         type="xsd:base64Binary"/>
  </message>

  <message name="doSpellingSuggestion">
    <part name="key"            type="xsd:string"/>
    <part name="phrase"         type="xsd:string"/>
  </message>

  <message name="doSpellingSuggestionResponse">
    <part name="return"         type="xsd:string"/>
  </message>

  <!-- note, ie and oe are ignored by server; all traffic is UTF-8. -->

  <message name="doGoogleSearch">
    <part name="key"            type="xsd:string"/>
    <part name="q"              type="xsd:string"/>
    <part name="start"          type="xsd:int"/>
    <part name="maxResults"     type="xsd:int"/>
    <part name="filter"         type="xsd:boolean"/>
    <part name="restrict"       type="xsd:string"/>
    <part name="safeSearch"     type="xsd:boolean"/>
    <part name="lr"             type="xsd:string"/>
    <part name="ie"             type="xsd:string"/>
    <part name="oe"             type="xsd:string"/>
  </message>

  <message name="doGoogleSearchResponse">
    <part name="return"         type="typens:GoogleSearchResult"/>           
  </message>

  <!-- Port for Google Web APIs, "GoogleSearch" -->

  <portType name="GoogleSearchPort">

    <operation name="doGetCachedPage">
      <input message="typens:doGetCachedPage"/>
      <output message="typens:doGetCachedPageResponse"/>
    </operation>

    <operation name="doSpellingSuggestion">
      <input message="typens:doSpellingSuggestion"/>
      <output message="typens:doSpellingSuggestionResponse"/>
    </operation>

    <operation name="doGoogleSearch">
      <input message="typens:doGoogleSearch"/>
      <output message="typens:doGoogleSearchResponse"/>
    </operation>

  </portType>


  <!-- Binding for Google Web APIs - RPC, SOAP over HTTP -->

  <binding name="GoogleSearchBinding" type="typens:GoogleSearchPort">
    <soap:binding style="rpc"
                  transport="http://schemas.xmlsoap.org/soap/http"/>

    <operation name="doGetCachedPage">
      <soap:operation soapAction="urn:GoogleSearchAction"/>
      <input>
        <soap:body use="encoded"
                   namespace="urn:GoogleSearch"
                   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </input>
      <output>
        <soap:body use="encoded"
                   namespace="urn:GoogleSearch"
                   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </output>
    </operation>

    <operation name="doSpellingSuggestion">
      <soap:operation soapAction="urn:GoogleSearchAction"/>
      <input>
        <soap:body use="encoded"
                   namespace="urn:GoogleSearch"
                   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </input>
      <output>
        <soap:body use="encoded"
                   namespace="urn:GoogleSearch"
                   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </output>
    </operation>

    <operation name="doGoogleSearch">
      <soap:operation soapAction="urn:GoogleSearchAction"/>
      <input>
        <soap:body use="encoded"
                   namespace="urn:GoogleSearch"
                   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </input>
      <output>
        <soap:body use="encoded"
                   namespace="urn:GoogleSearch"
                   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </output>
    </operation>
  </binding>

  <!-- Endpoint for Google Web APIs -->
  <service name="GoogleSearchService">
    <port name="GoogleSearchPort" binding="typens:GoogleSearchBinding">
      <soap:address location="http://api.google.com/search/beta2"/>
    </port>
  </service>

</definitions>
package com.crystaldecisions.data.xml.ws;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.client.OperationClient;

public class googleSearchTest2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			OMNamespace defNs;
			OMElement operation;
			MessageContext msgContext = null;
			defNs = OMAbstractFactory.getSOAP11Factory().createOMNamespace("",
					"");
			SOAPFactory omFactory = OMAbstractFactory.getSOAP11Factory();
			SOAPEnvelope envelope = omFactory.getDefaultEnvelope();
			envelope.declareNamespace(
					"http://schemas.xmlsoap.org/soap/envelope/";, "soapenv");
			envelope.declareNamespace(
					"http://schemas.xmlsoap.org/soap/encoding/";, "SOAP-ENC");
			envelope.declareNamespace(
					"http://www.w3.org/2001/XMLSchema-instance";, "xsi");
			envelope
					.declareNamespace("http://www.w3.org/2001/XMLSchema";, "xsd");

			operation = omFactory.createOMElement("doGoogleSearch",
					"urn:GoogleSearch", "ns1");
			envelope.getBody().addChild(operation);
			operation.addAttribute("soapenv:encordingStyle",
					"http://schemas.xmlsoap.org/soap/encoding/";, null);
			operation.addChild(getOMElement(omFactory, defNs, "key",
					"xsd:string", "xVQ1UNFQFHIRHbNGpvNqfBJhDZC/NXpz"));
			operation.addChild(getOMElement(omFactory, defNs, "q",
					"xsd:string", "shrdlu winograd maclisp teletype"));
			operation.addChild(getOMElement(omFactory, defNs, "start",
					"xsd:int", "0"));
			operation.addChild(getOMElement(omFactory, defNs, "maxResults",
					"xsd:int", "10"));
			operation.addChild(getOMElement(omFactory, defNs, "filter",
					"xsd:boolean", "true"));
			operation.addChild(getOMElement(omFactory, defNs, "restrict",
					"xsd:string", ""));
			operation.addChild(getOMElement(omFactory, defNs, "safeSearch",
					"xsd:boolean", "false"));
			operation.addChild(getOMElement(omFactory, defNs, "lr",
					"xsd:string", ""));
			operation.addChild(getOMElement(omFactory, defNs, "ie",
					"xsd:string", "latin1"));
			operation.addChild(getOMElement(omFactory, defNs, "oe",
					"xsd:string", "latin1"));
			msgContext = new MessageContext();
	        msgContext.setEnvelope(envelope);	        

			Options options = new Options();
			options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
			options.setTo(new EndpointReference(
					"http://api.google.com/search/beta2";));
			options.setAction("urn:GoogleSearchAction");
			options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE);
			ServiceClient serviceClient = new ServiceClient();
			serviceClient.setOptions(options);
			System.out.println(operation);
			OMElement response = serviceClient.sendReceive(operation);
            
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static OMElement getOMElement(OMFactory factory, OMNamespace ns,
			String elementName, String type, String text) {
		OMElement part = factory.createOMElement(elementName, ns);
		part.addAttribute("xsi:type", type, null);
		part.addChild(factory.createOMText(text));
		return part;
	}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to