編輯:關於Android編程
0-374-15012-5
段落
原文
譯文
phrase 3
The structure of a SOAP message is rigidly defined and is comprised of three major pieces.
SOAP消息結構嚴格定義並且由3個部分組成。
phrase 3-1
·The first piece is the SOAP envelope. This is essentially the container for all of the other SOAP data. The XML element name is Envelope and it’s always the root element.
第一部分是SOAP信封(Envelop,特定稱謂)。這基本上是所有其他的SOAP數據的容器。XML元素名稱是信封,它是根元素。
phrase 3-2
The second piece of a SOAP message is the SOAP header. This contains application-specific metadata relating to the request, such as encoding style, authentication information, etc. It’s considered optional and, in my experience, isn’t used all that often. The XML element name is Header and it’s a direct child of the Envelope element.
第二部分是SOAP的消息頭部,它包含了特定應用程序的與請求有關的元數據的格式,如編碼風格,身份驗證信息等等。它是可選的,根據我的經驗並不經常使用這一部分。XML元素名是Header,它是Envelope元素的直接子元素。
phrase 3-3
The final, and most significant, part of a SOAP message is the SOAP body. This contains the actual message request or response. The content of the SOAP body is application dependent and can be anything as long as its well-formed XML. The XML element name is Body and it’s also a direct child of the Envelope element. The data types used in the SOAP body are often defined in a service type definition such as a WSDL or WADL file.
最後也是最重要的是SOAP消息的主體部分。它包含了實際的請求和返回值的信息。SOAP的主體是依賴於應用程序的,可以是任何東西,只要是一個格式良好的XML文件。XML元素名是 Body,它也是Envelope元素的直接子元素。。在SOAP主體中使用的數據格式通常在諸如WSDL或者WADL文件一類的service格式定義文件中被定義。
phrase 4
One other SOAP element bears mentioning and that’s the SOAP Fault. You can only ever have one SOAP Fault and it appears in the SOAP body. SOAP Faults are used to indicate error conditions. If, for example, you’re trying to communicate with a web service that doesn’t understand the version of SOAP you’re using, it’ll respond with a SOAP Fault that indicates such. The XML element name is Fault.
另一個SOAP元素值得一提——SOAP故障。你只能有一個SOAP錯誤,它出現在SOAP主體中。SOAP錯誤用來指示錯誤條件。舉例來說,如果你想跟一個web service通信,但是它不理解你使用的SOAP的版本號,就會返回一個提示錯誤信息的SOAP錯誤。XML元素名是Fault。
phrase 5
For more information on SOAP, poke around on Google or check out one of the dozens of books on SOAP web services.
如果你想得到更多的SOAP信息,戳一下谷歌,或者查閱有關SOAP 網絡通信的書籍。
Part5
Speaking SOAP using ksoap2-android
說一說ksoap2-android的使用
phrase 1
If you’ve worked with other web service SDKs (e.g., .NET), you’ve probably used tools that can generate language type definitions from a web service definition file (e.g. WSDL). These kinds of tools abstract away a lot of the “SOAPiness” of web service communications. They keep your application code simple and easy to maintain. I’m sorry to tell you that, at the time of this writing, no such tool for ksoap2-android exists. You’ll have to get a bit more up close and personal with whatever service description your web service provides.
如果你用其他的web service SDK工作(比如.NET),你可能會使用一些,能夠從web service定義文件(如WSDL)中生成語言類型定義。這些各種各樣的工具抽象描述了網絡通信服務的很多“SOAPiness”[指soap(原意是肥皂)生成了很多soapiness(皂滑性),可以理解為增加了原wsdl文件的可操作性]。他們使得你的程序代碼變得簡單而且容易維護。很遺憾,在寫這篇文章的時候,針對ksoap2-android的解釋工具並不存在。你必須近距離接觸你的web service提供的各種服務描述文件。
phrase 2
Of the dozens of classes defined in ksoap2-android, there are only five that you’ll typically use – SoapPrimitive, SoapObject, SoapSerializationEnvelope, HttpTransportSE, and SoapFault. An understanding of these classes is all you need to perform a very simple SOAP request. I’ll discuss each one in turn and show you how you could invoke the “FindBookByISBN” SOAP request in the example above.
ksoap2-android中的幾十個類定義,只有5個你經常會用到SoapPrimitive, SoapObject, SoapSerializationEnvelope, HttpTransportSE,和 SoapFault. 為了執行一個簡單的SOAP請求,你需要理解這些類。我會以此討論每一個並向你展示如何調用上述例子中的“FindBookByISBN”SOAP請求。
phrase 3-1
SoapPrimitive類
A SoapPrimitive is just what it sounds like. It represents a serialized representation of a primitive data type in SOAP (floats, ints, doubles, strings, etc.) A SoapPrimitive doesn’t actually contain any type information, though. Everything is stored as strings. It’s up to the application developer to interpret and parse the contained data as appropriate.
SoapPrimitive顧名思義,它代表一個SOAP中序列化的原始數據類(浮點數、整數、雙精度浮點數、字符串等等)。但是SoapPrimitive並不包含實際意義上任何類型的信息。任何東西都是存儲成字符串類型的。由程序員解釋和解析裡面所包含的數據。
phrase 3-1-1
SoapPrimitive’s constructor looks like this.
SoapPrimitive的結構類型如下:
public SoapPrimitive(String namespace, String name, String value);
段落
原文
譯文
phrase 3-1-2
You usually won’t instantiate this yourself. In general, SOAP requests are more complex and require the use of the SoapObject, which I’ll discuss next. But it’s not uncommon to receive this as a response.
你通常不會實例化這個類,一般來說SOAP請求更加復雜,需要使用SoapObject,這個我接下來將會介紹 。而且將常收到這一類的回復。
phrase 3-2
SoapObject類
phrase 3-2-1
The SoapObject represents a complex type that’s defined for a given web service. These types are hierarchal data types composed of other data types and live in an application-specific namespace. The FindBookByISBN element used above is an example of a complex type.
SoapObject類表示一個給定的web service定義的復雜類型。這些數據類型是由層次結構的數據類型組成的其他數據類型並且活躍在一個由特定應用程序指定的命名空間中。上述例子中使用的FindBookByISBN元素是復雜數據類型的一個例子。
0-374-15012-5
段落
原文
譯文
phrase 3-2-2
SoapObject’s constructor looks like this.
SoapObject類的數據結構如下:
public SoapObject(String namespace, String name);
段落
原文
譯文
phrase 3-2-3
You can instantiate a SoapObject by passing in the object’s namespace and name into the constructor
你可以通過構造函數傳入對象的命名空間和名字來實例化一個SoapObject。
SoapObject findBookRequest = new SoapObject(
"http://services.example.com", "FindBookByISBN");
段落
原文
譯文
phrase 3-2-4
The FindBookByISBN method has a single parameter, ISBN. ISBN is a simple string. You might expect that you could simply wrap the ISBN inside of a SoapPrimitive and somehow add it into findBookRequest. That would be a perfectly reasonable approach. For some reason, however, SoapObject isn’t able to serve as a container for SoapPrimitives. Even more surprising is that it isn’t able to serve as a container for “AttributeContainer”, which is the parent class for both SoapObject and SoapPrimitive. A SoapObject can only contain other SoapObjects and another type of thing that SoapObject calls a property.
FindBookByISBN函數只有一個參數——ISBN。ISBN是一個簡單的字符串。你可能會認為你可以簡單地把ISBN封裝到SoapPrimitive,並且以某種方式添加到findBookRequest。這是一種非常合理的方法。出於某種原因,SoapObject不能作為SoapPrimitives的容器。甚至更讓人驚訝的是,它也不能作為屬性容器“AttributeContainer”(是SoapObject 和 SoapPrimitive的父類)而存在。一個SoapObject只能包含其他的SoapObjects,以及另外一種SoapObject稱之為屬性的東西。
phrase 3-2-5
What’s a property? It’s really just another way to represent a SOAP primitive. This may seem like a strange design decision to you. It seems like a strange design decision to me too. But I imagine the library designers had a good reason for doing it this way. In any case, if you want to add a primitive to a SoapObject, you’ll want to use the addProperty method.
什麼是屬性?這只是另一種用來表示SOAP原語的方式。對於你來說,可能看起來很奇怪。對我來說,看起來也很奇怪。但是我假設這個庫文件的設計者這樣做是為了一個好的目的。無論如何,如果你想要增加一個原語到SoapObject,你就會用到addProperty這個函數。
findBookRequest.addProperty("ISBN", "0-374-15012-5");
段落
原文
譯文
phrase 3-2-6
The addProperty method accepts two arguments. The first argument is the name of the parameter or property to add. The second parameter is the actual value of the property.
addProperty函數接受兩個標識符,第一個標識符表示想要添加的參數名。第二個標識符表示前面添加的參數的實際值。
phrase 3-3
SoapSerializationEnvelope類
phrase 3-3-1
Once you have the SoapObject that represents your request, you’ll need to wrap it in a SOAP envelope. ksoap2-android has a couple of classes for working with SOAP envelopes, but the one you’ll most often use is the SoapSerializationEnvelope.
一旦你使用SoapObject表示你的請求,你需要把它封裝到SOAP envelope裡面。ksoap2-android有兩三個類是與SOAP envelopes工作的,但是其中你經常會用到的是SoapSerializationEnvelope類。
phrase 3-3-2
If you browse through the library, you might notice a class called SoapEnvelope and wonder why you wouldn’t use that instead. SoapEnvelope is actually the base class for SoapSerializationEnvelope. Both classes serve as containers for the SOAP message header and body. And both provide mechanisms to serialize/deserialize SOAP data. But the problem with SoapEnvelope is that it doesn’t support SoapObjects or SoapPrimitives. It can only deal with kXML Node types. It’s geared more towards the scenario where you manually build up your own SOAP data structure using kXML and then hand it off to SoapEnvelope for serialization. It’s not very convenient to work with and since you’ll almost always be dealing with SoapObjects or SoapPrimitives, you’ll need to use the SoapSerializationEnvelope.
如果你浏覽了類庫文件,你可能會注意到一個名叫SoapEnvelope的類,然後疑惑你為什麼不用這個類來代替。SoapEnvelope是SoapSerializationEnvelope的基類。兩個類都作為SOAP信息的頭部和主體的容器。兩個類同時提供SOAP數據進行序列化/反序列化的機制。但是SoapEnvelope存在的問題是,它不支持SoapObjects也不支持 SoapPrimitives。它只能處理kXML節點類型的數據。它更適合於你利用kXML手動建立自己的SOAP數據結構,然後交給 SoapEnvelope進行序列化。它並不便於使用因為你總是一直在處理SoapObjects或者SoapPrimitives,所以你還是需要使用SoapSerializationEnvelope。
phrase 3-3-3
SoapSerializationEnvelope’s constructor looks like so.
SoapSerializationEnvelope類的結構如下:
public SoapSerializationEnvelope(int version);
段落
原文
譯文
phrase 3-3-4
The constructor accepts one argument – the version of SOAP you intend to use. You might use it like so.
構造函數值接受一個參數——你想要使用的SOAP的版本號。你可能會這樣使用。
SoapSerializationEnvelope soapEnvelope =
new SoapSerializationEnvelope(SoapEnvelope.VER12);
段落
原文
譯文
phrase 3-3-5
All of the supported versions of SOAP are defined as constants in the SoapEnvelope base class. The versions of SOAP that are currently supported are 1.0, 1.1, and 1.2. The version you choose is dependent on the versions supported by the web service. Consult the web service documentation to see what it supports.
所有支持工作的SOAP的版本號,在SoapEnvelope基類中被定義成常量。目前為止支持的SOAP版本號是1.0,1.1,1.2。你選擇的版本號由你的web service支持的版本決定。查詢web service 文檔看看它支持的版本號。
phrase 3-3-6
Now you can finally add your request object to the envelope by using the setOutputSoapObject() method.
現在你可以通過使用setOutputSoapObject() 函數添加你的請求對象到envelope。
soapEnvelope.setOutputSoapObject(findBookRequest);
段落
原文
譯文
Part6
What about SOAP headers?
什麼是SOAP header
phrase 1
SOAP headers seem to have been a bit of an afterthought in the design of ksoap2-android. There is no class in the library that represent a SOAP header. The handling of all the header data is managed by the SoapEnvelope base class. And as you might guess from my earlier comments concerning SoapEnvelope, SOAP headers are specified using a kXML data type – Element.
SOAP header看起來像是ksoap2-android裡面馬後炮的東西。在庫文件中並沒有類表示一個SOAP header。對SOAP header數據的處理都受SoapEnvelope基類的管理。正如你可能會像我之前對SoapEnvelope所作出的評論一樣猜測,SOAP header使用特定的kXML數據類型——Element。
phrase 2
SoapEnvelope has a member variable called headerOut, which is declared as an array of Elements. By default this is null, which results in an empty SOAP header element when serialized. To specify your own set of headers, instantiate a new Element array and populate it appropriately for your application. Here’s an example of how you might do this for some fictional authorization header.
SoapEnvelope有一個成員變量headerOut,聲明為Element類型的數組。默認為null,導致序列化的時候SOAP header element是空值。指定你自己的header集合,實例化一個Element數組並且為了你的應用程序適當填充。這裡有一個例子,header是虛構的但是被認可的。
final String SERVICE_NAMESPACE = "ServiceNamespace";
Element authHeader = new Element();
authHeader.setNamespace(SERVICE_NAMESPACE);
authHeader.setName("authHeader");
Element username = authHeader.createElement(SERVICE_NAMESPACE, "username");
username.addChild(Node.TEXT, "skirk");
authHeader.addChild(Node.ELEMENT, username);
Element password = authHeader.createElement(SERVICE_NAMESPACE, "password");
password.addChild(Node.TEXT, "mypassword");
authHeader.addChild(Node.ELEMENT, password);
soapEnvelope.headerOut = new Element[] { authHeader };
If you know or suspect that your web service was implemented using .NET, set SoapSerializationEnvelope’s dotNet property to true. SoapSerializationEnvelope provides special SOAP encoding support for .NET web services.
如果你懷疑或者知道你的web service使用的是.NET,將SoapSerializationEnvelope設置成true。SoapSerializationEnvelope提供了.NET特殊的SOAP編碼支持。
段落
原文
譯文
Part6
HttpTransportSE
phrase 1
With the SOAP request packaged up in a SoapEnvelope, you’re now ready to send the request to your web service. The SOAP specification allows for any transport mechanism. If you wanted to use SMTP or FTP, for example, you totally could (assuming your web service supported it). But you would have to implement the protocol level support for one of these yourself. Out of the box, ksoap2-android only supports HTTP. And since this is the protocol used by 99% of all web services, you can rest easy knowing that all the hard work has been done for you.
隨著SOAP請求封裝到SoapEnvelope中,你已經准備好發送請求到你的web service了。SOAP機制允許所有的傳輸機制。例如,如果你想使用SMTP或者FTP,你完全可以這樣做(假設你的webservice支持這種傳輸機制)。但是你必須執行協議級別支持其中一個。現在可用的 ksoap2-android只支持HTTP協議。因為這種協議支持99%的webservice,因此你可以高枕無憂,所有的辛勤工作已經完成。
phrase 2
HttpTransportSE is the class you’ll use for communicating with web services over HTTP. In case you’re curious, the “SE” part of the class name means that it’s built around J2SE classes. There’s actually another class, HttpTransport, that’s built around the J2ME connection framework. It’s included as part of the ksoap2-android library, but I’m not entirely sure why you would ever choose this over HttpTransportSE.
HttpTransportSE是你會通過HTTP協議與webservice進行通信的類。如果你表示對“SE”感到好奇,它是類名稱的一部分,意味著它是建立在J2SE類基礎上的。事實上有另外一個類,HttpTransport,它是建立在J2ME鏈接框架上的。它包括在ksoap2-android中,但是我不是很確定為什麼選擇這個而不是HttpTransportSE。
phrase 3
To perform a SOAP request, construct an instance of HttpTransportSE and invoke the call method on the instance.
為了執行一個SOAP請求,構建 HttpTransportSE,並且實例化call函數。
HttpTransportSE htse = new HttpTransportSE(
"http://www.example.com/mywebserviceurl");
htse.call("http://www.example.com/mywebserviceurl/FindBookByISBN",
soapEnvelope);
未完待續………………
原文地址:Mina SSLFilter(Apahce Mina user guide Chapter11 SSL Filter)SslFilter過濾器是負責管理數據的加
Android系統根據生命周期的不同階段喚起對應的回調函數來執行代碼。系統存在啟動與銷毀一個activity的一套有序的回調函數。本節來討論下不同生命周期的回調函數裡都該
本文實例講述了Android實現九宮格(GridView中各項平分空間)的方法。分享給大家供大家參考。具體如下:項目需要做一個九宮格(也不一定是9的,4宮格、16宮格、4
項目需要做了一個調節屏幕的工具類/* * Android調節屏幕亮度工具類 * by itas109 * http://blog.csdn.net