Dollars
using System.Runtime.Serialization;
using System.Linq;
[DataMember]

list 2.18 XML metadata defined class hierarchy
complex type in the code to the general form of the class implementation. Complicated further by increasing the special structure of the class inheritance relationship is defined. In this way, a common type such as “price” can be derived for a more specific type, such as “stock price” or “house price”. WCF supports the WSDL through the appropriate representation of the class hierarchy, the class structure and between XML serialization and deserialization are also removed from the properties of each class and add to a collection.


2.17 in the list, the class of Price by the three elements and a sub-classes. StockPrice, inherited from Price. Namespace applied to the two classes so they perfectly legal in XML by the name of. Each element retains its own namespace.
list 2.19 SOAP message body serialization class hierarchy


[DataContract (Namespace = "http://EssentialWCF/Price/")]


namespace Stock
XML metadata to generate these two lists are used to support the basis for the relationship shown in 2.18. Price XML metadata displayed first, followed by shows StockPrice XML metadata. Note StockPrice Import Price metadata. Note that in the XSD, all elements are defined with minOccurs = 0, because they are not in the code using [isRequired = true] to define a property.
2.17 using data contract defines a list of the class hierarchy

{
public DateTime CurrentTime;
publiclong DailyVolume;
2011 年 06 月 23 日
[DataMember]
< img src = "http://img.feedsky.com/images/icon_subshot01_580k.gif" onClick = "window.open ( ttp://img.feedsky.com/images/icon_subshot01_580k.gif " onerror = "this . src = ttp://cache.soso.com/img/blog/p1.gif "onload =" addjustimg (this) "TYPE =" audio / mpeg ">
2006-12-13T21 :18:51.313-05: 00


[DataMember]




using System.Text;
}

publicstring Ticker;
{
publicdouble CurrentPrice;
using System.Collections.Generic;
[DataMember]
[DataMember]
xmlns: i = “http://www.w3.org/2001/XMLSchema-instance”>
[DataMember]

xmlns: xs = “http://www.w3.org/2001/XMLSchema”>
StockPrice type of a serialized SOAP message body is displayed in the list 2.19. Note that the namespace Price and StockPrice entirely through the SOAP message body be moved from the code list list 2.17 2.18 in the XML metadata.
}
msft
[DataContract (Namespace = "http://EssentialWCF/StockPrice")]
publicdouble DailyChange;
}
using System;
100

0.012345

{
publicstring Currency;
450000
publicclass StockPrice: Price



2009, graduated from Dalian University of Technology Department of Computer Science, from the microcontroller to write assembly and C started, to 2006. NET platform, so far. hobbies are football, reading. read many books, such as “data mining” “CSharp Advanced Programming (Volume II)” “Ren Management Log” “the essence of the operating system and design principles,” “currency wars 2 money forces, “” Red Rock “,” Haideliangmoli “” Li Ka-shing “” Investment “” Laozi and Zhuangzi, “” The Wealth of Nations “” Theory of Moral Sentiments. “translation is” Essential Windows Communication Foundation “, a book.
publicclass Price

Bytes array, DataTime, TimeSpan, Guid, Uri, XmlQualifiedName, XmlEle ment and XmlNode
class members m_CurrentPrice, m_CurrentType and m_ticker symbol will certainly, however m_dailyVolume and m_dailyChange not. Non-class members will certainly exist in the XML instance can be based on negligence, and they are still being felt XSD is legal. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization; using System.ServiceModel; namespace EssentialWCF {[DataContract (Namespace = "http://EssentialWCF", Name = "StockPrice")] public class clsStockPrice {[DataMember (Name = "CurrentPrice", Order = 0, IsRequired = true)] public double theCurrentPriceNow; [DataMember (Name = "CurrentTime", Order = 1, IsRequired = true)] public DateTime theCurrentTimeNow; [DataMember (Name = "Ticker", Order = 2, IsRequired = true)] public string theTickerSymbol; [DataMember (Name = "DailyVolume", Order = 3, IsRequired = false)] public long theDailyVolumeSoFar; [DataMember ( Name = "DailyChange", Order = 4, IsRequired = false)] public double theDailyChangeSoFar;} [ServiceContract] public class StockService {[OperationContract] private clsStockPrice GetPrice (string ticker) {clsStockPrice s = new clsStockPrice (); s.theTickerSymbol = ticker; s.theCurrentPriceNow = 100.00; s.theCurrentTimeNow = DateTime.Now; s.theDailyChangeSoFar = .012345; s.theDailyVolumeSoFar = 450000; return s;}}} Svcutil.exe t: metadata called for the use of classes defined in the [DataMember] elements generated XSD. The list 2.15 2.16 reveals a list of the code generated XSD. Beware of the order is based on the temperature of the element name in the code attribute definition. Must also beware of non-class members will certainly be defined in the XML metadata into a minOccurs = 0. Example class to ensure its height and width values ??stored always non-negative jiao.jiaoxuefa.com,
class member name in the code are used m_ prefix. Class member name is overloaded so m_notation no need to introduce the service interface defined in the XSD.
symbol [Serializable] types, members did not help with [NonSerializable] symbol
symbol [CollectionDataContract]
symbol types [Serializable] types and end the ISerializable interface
symbol [ DataContract] and [DataMember] attribute list of the types
2.15 shows a class definition, StockPrice, 5 Columbia public data members. Three, ticker, theCurrentPrice and theCurrentTime certainly have, because they use isRequired = true symbol. Some additional [DataMember] personality revealed in the following:
array and aggregation, such as List , Dictionary and Hashtable
in a service within the functional use by the end of the code . Surface in the service, functional services defined in WSDL. In a WCF service, easy to use and process data in mixed types of representation; while in the service surface, using process data from the XML metadata defines said. WCF data contract for the supply of the code definitions. NET CLR types and definitions used in the service the W3C XML metadata surface communication between the definitions irradiation.
using WCF, developers spend more effort in the code and interface semantics, syntax in the XSD and WSDL will spend less effort. XSD and WSDL is not to say that grammar is not important; they are cross-platform interoperability held a monopoly on essential prerequisite. However, the compiler also revealed by the in the. NET language translation of the generated data structure with cross-platform interoperability of XSD and WSDL monopoly that advantage.
[DataContract] attribute, defined in the System.Runtime.Serialization explained in the description of a class deserve to XSD in the WSDL service leaked out. If a class has not [DataContract] attribute, it will not show the current WSDL. The default, XML metadata names and class names and metadata in the target namespace is the same: http://schemas.datacontract.org/2004/07 (by. NET namespace description). Both can be overloaded. You might want to override them to curb the surface leak in the service name. For example, regOrder an internal class name in the Order in the XSD can leak out. 2.16 reveals a list of the names in case of overload and XSD namespace.
[DataMember] attribute, also defined in the System.Runtime.Serializationwww.yinbiao.org, will determine the [DataContract] attribute defines the members included in the XML metadata. In case a member of the class did not help with the [DataMember] to define the attributes, not included in the XML metadata, although it is a class member. By default, class members are not included in the XML metadata definition, this is a choice model. . NET class member of the range, whether public or private, does not affect whether it is included in the XML metadata; be decided by the [DataMember] to severely limited.
built initial CLR types, such as int32 and string
class members of the order by the [DataMember] attribute. In case the order is not [hot] credit card no annual fee for life can be? Bank is somewhat non-permissive _ credit card information has been determined, the element will be in the XSD arranged in alphabetical order. Order is unimportant trivial, but to curb the monopoly of the order is very important for each other. In case you are looking to send a message to a specific measure in order to receive service messages, to curb this property to XML text encoding sequence elements.
a. NET class definition XML metadata
DataContractSerializer serialization type and speak in the WSDL contract leaked them, if they are Italian the following conditions:
inherited from the type
pieces IXmlSerializable For
at the design stage, [DataContract] attribute is used to indicate which class and deserve to be expressed in XSD in the WSDL service leak. [DataMember] attributes which further define the XSD class members deserve included in the surface representation. Run-time, DataContractSerializer class to use [DataContract] and [DataMember] legal to serialize an object into XML. 2.7 reveals a picture. NET ended with each other to end the monopoly system and other XML metadata that.
2011 年 07 月 22 日
2.8 also reveals the picture depicted in the same translation of 2.7, while also revealing to determine the C # and XSD syntax.

2.27 a server from the list to expose a collection using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization; using System.ServiceModel; namespace EssentialWCF {[DataContract (Namespace = " http://EssentialWCF ")] public class StockPrice {[DataMember] public double CurrentPrice; [DataMember] public DateTime CurrentTime; [DataMember] public string Ticker;} [CollectionDataContract] public class StockPriceCollection: List {} [ServiceContract] public class StockService {[OperationContract] private StockPriceCollection GetPriceAsCollection (string [] tickers) {StockPriceCollection list = new StockPriceCollection (); for (int i = 0; i list 2.26 shows two an equivalent data contract. Service contract by the end of the first exposure; second category described by the client. These two contracts are equivalent and generate a unique XML metadata definition. In the server, by default, WCF will be on the XML elements in alphabetical order, so the metadata will force the second data element in alphabetical order. Because the name is “StockPriceSvc” and the name of “Currency” of the existence of separate property items defecate annual fee credit card machine consumers of new rules in the DataContract and DataMember, XSD to survive in the second contract and the contract first the same.
list 2.27 shows a collection of data using the contract and operation. This collection uses [CollectionDataContract] property to qualify, it is especially used to provide this purpose a special property of the WCF. This property is any guide WCF to support the IEnumerable interface and implements the Add method of an array type sequence into XML. StockPriceCollection class inherits from the List class, List class inherits from the base class interface to implement ICollection serialization. equivalent data contract
If you are using WCF to expose service and use svcutil.exe to create access service code, under normal circumstances you do not care about the client and service side of the line between the transmission of messages said. To know a WCF data contract. NET type sequence into an XML message set and talk about a sequence of XML information sets into a counter. NET type. XML Information Set be online to file or binary code, which depends on the communication process used in the binding, but again,. NET code is not aware of the existence of coding. This way you like to use in your code. NET type, but a set of standards-based XML encoding of that information on the specific transmission line.
2010 年 10 月 21 日
collection is. NET is very convenient data structure, which focused on the dynamic memory allocation, point to enumerate and list the advantages. Although useful, but there is no XSD or a set of standards and WCF equivalent. So, say a collection of serialized XML, WCF needs to be set in accordance with an array of treatment. In fact, a collection of online serialization level is consistent with an array. In addition to the collection (the type that inherits from ICollection ), this is the same, because it inherits from IEnumerable type or IList .
List 2.26 equivalent data contract using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization; namespace EssentialWCF {[DataContract (Namespace = "http://EssentialWCF")] public class StockPriceSvc / / V1 {[DataMember] public double CurrentPrice; [DataMember] public DateTime CurrentTime; [DataMember] public string Ticker; [DataMember] public string Currency;} [DataContract (Namespace = "http://EssentialWCF", Name = "StockPriceSvc")] public class StockPrice / / V2 {[DataMember (Order = 2)] public double CurrentPrice; [DataMember (Order = 3)] public DateTime CurrentTime; [DataMember (Order = 4)] public string Ticker; [DataMember (Order = 1, Name = "Currency ")] public string Money;}} to use set
However, there are many cases when you want the client and server use different types. If the client and server are developed by different organizations, then it is likely, or just the communication is the use of unilateral WCF. In fact, if you do not apply, or add a service reference svcutil.exe to generate the client proxy, the client will be a great member of a member name and server name different situations may occur. However, by using the [DataMember] attribute to control these names, you can let them in the XML representation is the same. As long as the client and server use an equivalent XML representation of the WCF, the deserialize the XML into a different message. NET type is possible. If the two sequences into the same class of XML metadata, data contracts that these classes can be considered the same. Contract for the data to be consistent, they must have the same namespace, name and members. XML data members must be the same name and in the same position. Brief that they have online are indistinguishable.

Roughly as follows: Since the database design is not very reasonable, and EPS through stock price to calculate the PE, so the first time is more like a function, this function as a column, can be displayed easily.
using (SqlConnection conn
SqlDataReader datareader = cmd.ExecuteReader ();
}
string columnName = “”;
conn.Open ();
tableName = “StockPriceSZ_SP”;
}
using System.Data;
1: VS2008 to create a database SqlServer project
string tableName = “”;
{
so similar, but the exec function does not allow food and other kind of statement. so at a loss. remorse original design table is too casual.
2: Create a class code code code that makes up the stock by judge Remove the corresponding SQL statement date stock price
RECONFIGURE;
{
public partial class UserDefinedFunctions
columnName = “sz” StockCode;
decimal result = 0;
However, due to improper design database, this function needs to generate the statement that I need to write the function in EXEC SP_EXECUTESQL @ STR
CREATE FUNCTION [dbo]. [ufn_StockPrice] (@ StockCode nvarchar (6 ), @ ReportTime nvarchar (10))
FROM : \ Chengxu \ Modules.dll — dll location for
result = Convert.ToDecimal (datareader.GetValue (0). ToString () );
public static SqlMoney ufn_StockPrice (string StockCode, string ReportTime)
4: Use the time you can use this function select StockCode, ReportTime, [dbo]. [ufn_StockPrice] (StockCode, ReportTime), * FROM ***
sp_configure lr enabled 1; – open database CLR
3: (can be deployed to the corresponding database, provided that the solution properties of the configuration, the connection string)
GO

AS
using Microsoft.SqlServer.Server;
}
— Custom number of rows bound to dl the corresponding method.
= new SqlConnection (“context connection = true”))
drop ASSEMBLY [Modules]
else
solve the problem.
EXTERNAL NAME [Modules]. UserDefinedFunctions.ufn_StockPrice
{
using System.Data.SqlTypes;
[Microsoft.SqlServer.Server.SqlFunction (DataAccess = DataAccessKind.Read)] < br /> if (prex == “6″)
tableName = “StockPriceSH_SP”;
columnName = “sh” StockCode;
2010 年 06 月 20 日
GO < br /> CREATE ASSEMBLY [Modules]
out when the program encounters a problem. Environment VS2008 SQL2005
{
SqlCommand cmd = new SqlCommand [original] credit card no annual fee for life can be? Bank is somewhat non-permissive _ credit card information (“SELECT ISNULL ([" columnName "], 0) FROM [" tableName "] WHERE PDATE = quot; ReportTime ” “, conn);
};
also be able to compile. The compiled dll file saved to a location
by using C # CLR can solve the database can not solve the problem.
{
RETURNS money
prex = StockCode.Substring (0, 1);
Pan brother later found a solution.
}
using System.Data.SqlClient;
if (datareader.Read ())
return result;
string prex = “”;
}
WITH PERMISSION_SET = SAFE
{
using System;
Note: If an error occurs, increase the database compatibility mode, then run, then compatibility mode to change back to OK .

Date Open High Low Close Volume Turnover

WHILE @ @ FETCH_STATUS = 0
– all of the stock price into the temporary table
StockPrice.xml file:
GO
FROM OPENROWSET (BULK #39;D: \ Merchants Securities accessible information \ T0002 \ export \ CASE WHEN @ StockCode LIKE % THEN H ELSE Z END @ StockCode TXT #39;, FORMATFILE = #39;D: \ StockPrice. xml #39;) AS t1
< br /> FETCH NEXT FROM CUR_TMP INTO @ StockCode;

Step Three:
SELECT @ SQL = lt;br /> – define a list of current stock market cursor
END

D: \ StockPrice.xml defined xml file


D: \ Investment Securities Mastery letter \ T0002 \ export \ SZ000001.TXT is the data source file path
StockCode, TradingDate, [Open], [Close], High, Low, Volu me, Amount

– per share to take the first right to re-price
CLOSE CUR_TMP;
OPEN CUR_TMP;
Sql server2010-09-21 09:19:08 Read 2 Comments 0 Word Count: Example: The 1892 stock price into the database, format: a stock accessible information from a senior export file Export data formats (non-data line skip)
FROM OPENROWSET (BULK : \ Merchants Securities Mastery letter \ T0002 \ export \ SZ000001.TXT FORMATFILE = : \ StockPr ice.xml AS t1

FETCH NEXT FROM CUR_TMP INTO @ StockCode;

key statement:
INSERT INTO tempdb.dbo.StockPriceForward (



< FIELD ID = "2" xsi: type = "CharTerm" TERMINATOR = "\ t" MAX_LENGTH = "41" />
DEALLOCATE CUR_TMP;

as follows
)
INSERT INTO information.StockPriceForward (
Step 1: According to the data source file defines an XML file



the temporary table data into the target
DECLARE @ StockCode nvarchar (6), @ SQL nvarchar (max);
SELECT 00001 TradingDate, [Open], [Close], High, Low, Volum e / 100, Amount
BEGIN
TRUNCATE TABLE information.StockPriceForward;
EXEC (@ SQL);
can be achieved using the cursor to import all of the stock price,
Step two:
FROM information.uv_Stock
2010 年 09 月 21 日
SELECT #39; StockCode #39; TradingDate, [Open], [Close], High, Low, Volume/100 , Amount
DECLARE CUR_TMP CURSOR LOCAL FAST_FORWARD FOR
for the environment: the price is updated daily, before the right to re-price more special, know that the stock of knowledge should know, such as a stock sent shares after the price of the previous need a fresh calculation again.

WHERE IssuingDate IS NOT NULL AND ListingDate IS NOT NULL AND DelistingDate IS NULL;
2008-01-02 22.09 22.96 21.59 22.32 13158390 709842240.000
2008-01-03 22.09 22.32 20.65 2 SMS credit card fraud due to the new annual fee bait 1.19 21134656 1065804736.000
StockCode, TradingDate, [Open], [Close], High, Low, Volu me, Amount
data source:


Create a job, you can bulk import data, daily from accessible information to do is download the latest software on the stock ex-dividend data.

as SZ00001.TXT …..

SELECT StockCode
)

ORDER BY
WHERE
public.stockprice
# connect to the database
sz <- sqlQuery (channel, "
FROM
database a total of 7.086 million lines, data 388MB , index 213MB total 600MB. check the first week of data queries commercial banks scramble for unlimited credit card charges can not waiver on the cake 587 years line with 281ms, after several times of 47ms and 63ms, check on the data line 2846, spending 125ms.

And, like ASMX, WCF also provides a robust expansion model. But in addition to using the HTTP pipeline, it also uses the channel stack. WCF in the channel is very flexible. They understand the transport protocol such as HTTP, but also to understand other elements such as security and transaction protocol. Channel stack in the third chapter, “channel” and Chapter IV “binding” in the description.
Table 7.1 WCF service in a feature set allows ASMX
list ASMX 7.5 session state access and configure settings using System.ServiceModel; using System.Runtime.Serialization; using System.ServiceModel.Activation; using System . Web; using System.Configuration; namespace Services {[DataContract] public class StockPrice {/ / [DataMember] public string source; [DataMember] public double price; [DataMember] public int calls;} [ServiceContract] public interface IStockService {[ OperationContract] StockPrice GetPrice (string ticker);} [ServiceBehavior (InstanceContextMode = InstanceContextMode.PerSession)] [AspNetCompatibilityRequirements (RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] public class StockService: IStockService {public StockPrice GetPrice (string ticker) {StockPrice p = new StockPrice ( ); int nCalls = 0; if (HttpContext.Current.Session ["cnt"]! = null) {nCalls = (int) HttpContext.Current.Session ["cnt"];} HttpContext.Current.Session ["cnt" ] = nCalls; p.calls = nCalls; p.price = 94.85; / / p.source = ConfigurationManager.AppSettings ["StockSource"]; return p;}}}
1. HTTPContext.Current. in ASP.NET HTTP pipeline set to null. In a WCF service, you can use OperationContext.Current object to achieve a similar purpose.
WCF support IIS in a special boarding model: ASP.NET compatibility mode. When running in this mode, time, ASP.NET for WCF services hosted environment. Thus, in and is legal. However, not all of the ASP.NET HTTP features are enabled in this mode:
list of 7.7 on the client configuration file manipulation to Cookies

2010 年 12 月 27 日
4. session state
(2) globalization. You can set the thread culture in the region to access international part.

in ASP.NET compatibility mode is turned on, the service can take advantage of ASP.NET features. 7.5 in the list, we use two ASP.NET features. First, we use the ASMX-SessionState feature to store session layer state. Instance can be set to PerCall, PerSession or Single. The fifth chapter in the “behavior” was further defined. In this example, we use PerSessino, so many times if a client calls the service using the same proxy, session state will be preserved between different calls. WCF has a lot of other ways to store session layer data, but for those who are familiar with ASMX, this is a convenient framework. Second, we use the familiar in web.config AppSettings section to store application-specific configuration data. In the service-side code, ConfigurationManager object AppSettings collection to collect these values.
WCF and ASP.NET impersonation in the open. NET 1.X implementation in the same way. By section of the web.config file contains achieve. When you do this, the client-side validation is automatically sent to the server, the server uses client-side validation to perform the operation.
before the WCF, ASMX is ASP.NET Web Service in a common approach. It needs a public Web service, and excellent support provided by the ASP.NET HTTP pipeline robust expansion capabilities. In WCF, the service is designed to separate transmission and do not understand their boarding model. So WCF service can not rely on the implementation of the HTTP pipeline within such HTTP.SYS.
5.
3. imitate
3. imitation. WCF supports the use of behavior in the service layer and the operation layer. This is the additional implementation of ASP.NET. If the service through the WCF imitation, will override settings in ASP.NET. If the service does not implement imitation, ASP.NET will use the rules.
list 7.8 enables simulation using System.ServiceModel; using System.Runtime.Serialization; using System.ServiceModel.Activation; using System.Web; using System.Configuration; using System.Security.Principal; namespace Services {[DataContract ] public class StockPrice {[DataMember] public double price; [DataMember] public string requestedBy;} [ServiceContract] public interface IStockService {[OperationContract] StockPrice GetPrice (string ticker);} [ServiceBehavior] [AspNetCompatibilityRequirements (RequirementsMode = AspNetCompatibilityRequirementsMode.Required) ] public class StockService: IStockService {[OperationBehavior (Impersonation = ImpersonationOpti on.Required)] public StockPrice GetPrice (string ticker) {StockPrice p = new StockPrice (); p.requestedBy = WindowsIdentity.GetCurrent (). Name; p.price = 94.85; return p;}}}
list of 7.6 in the service configuration to enable ASP.NET compatibility < service behaviorConfiguration = "MEXServiceTypeBehavior" name = "Services.StockService">
4. session state. This is entirely inherited from the ASP.NET configuration implementation. You can use the process, service or continuous structure to hold the SQL state.

List 7.8 shows the operational level simulation setting, assuming it is not allowed in the web.config of the service layer. When a client access server, the user is logged in as a member in RequestedBy return. If the operation behavior is removed, RequestedBy members default to wind back the network services. Simulations in Chapter 8, “Security” details.
7.7 shows how to list the client configuration file to enable cookies. this list by the Add Service Reference in Visual Studio generates. Note that the default allowCookies set to true.
In order to run in ASP.NET compatibility mode on the ASP.NET feature, you need to change two settings. In the application layer, you have to set in web.config / / to true. Because the service layer ASMX is a choice to enter the mode, you must not set in the service layer AspNetCompatibilityRequirements to Allowed. With these two settings, almost all of the ASP.NET features can be used in a WCF service. Table 7.1 describes the relationship between these two settings.
work to make PerSession instance, the client must identity in order to save a session from the client to the server in the order calling the session ID can be returned to the server. For ASP.NET, which is transmitted through the HTTP header in a client cookie to achieve. In order to work through the ASMX-PerSession instance, the client must open the cookies. Because the standard HTTP bindings, basicHttpBinding and wsHttpBinding, by default does not allow cookies, you must define a client app.config AllowCookies = true binding configuration . 7.6 shows the list of server enable aspNetCompatibility.
6. ConfigurationManager.AppSettings. You can only root node in the web.config or the application of the above to obtain a virtual set, because httpContext is empty.
2. File / Url certification
However, there are some need further explanation.
1. HTTPContext.Current. ConfigurationManager.AppSettings and ConfigurationManager.GetSection simultaneously. HttpContext.Current flow between threads in the WCF.
so that you can use to mimic any one of two ways. In order to set it in the service layer, the use of the service behavior impersionateCallerForAllOperations = true, the operation behavior using ImpersionationOption.Allowed. In order to open it in the operating level, the operation behavior using ImpersonationOption.Required, while not in service behavior in reference to anything.

[MessageContract] attribute defines the SOAP message structure. This property is not too much sugar, because its purpose is to define the boundaries of the message rather than the message content itself. The only modification is the body of the message on how many parcels into a single SOAP message, determine whether to include all, if that is the case, also need to determine Warpper name and namespace.
2010 年 10 月 22 日
In order to use [MessageContract] types of messages generated on behalf of the client proxy code, you need to check the Add Service Reference dialog box is always senior to generate a message contract options, as shown in picture 2.9. 2.31
list typed messages using a non-contract the client initiates the communication
Whether you are using a typed or untyped messages, you may want to transfer the SOAP message header information and is not a SOAP message body. A common requirement is sent with the message session state or context information. Therefore, in addition to creating additional packaging information, SOAP message header is a convenient and easy to understand the structure of the transmission of messages.
types of messages using a non-SOAP message header
type of news you might want to define a lot of message header or message body if they are different levels of the client software to use. For example, a level of need associated with the SOAP message header to the message as a request message generated Response. Also another level may want to determine the message so that it can be appropriate to forward the message. In this case, the first two messages have their own purpose, there is no reason to merge them into a structure to go.

typed messages using [MessageHeader] and [MessageBodyMember] attribute to describe the SOAP message headers and body structure. Client and server can use the sequence of object references this data. SOAP message headers associated with additional information such as name and namespace, regardless of whether the message will be delayed, or which side is the final end and the recipient. Additional information can also be associated with the SOAP message body, such as name and namespace. If you use more than one message body, MessageContract can define the order of these parts. Message header and message body can have simple or complex type definition.
2.30 shows a list using the message type as input and output operations contract. Note that the message GetBody method is a common anti-serialized into the message body types. This method uses an XMLReader to read the SOAP message elements. Because it uses an XML reader, make can be read once; if you want to read more than once elements, you should use the message CreateBufferCopy method. Re-side SOAP operation name is the name of the requested action followed by the “Response” suffix. This can be [OperationContract] attribute (ReplyAction =) to reload.
2.34 client list to a non-typed message into the message header
contract through using direct access to the SOAP message header and message body sent to a service providing a service and to receive from the SOAP message complete control. This allows the use of simple or complex type to define the precise content of the SOAP part. Like when you need full control of data serialization when you convert from DataContractSerializer to XmlSerializer, when you need full control of the SOAP message when you convert from DataContracts to MessageContracts.
Message class by a number of create, read and write the message content. Client is responsible for the message sent to the server before the server is responsible for creating the message and creates a return message. Before sending the message, the content must be placed in the message body. This can be CreateMessage, WriteMessage or WriteBody methods.

list 2.35 shows the code generated by the client-side SOAP message. Note inserted into the appropriate namespace the TimeZone element in the message header. 2.32
list messages using a non-contract type of the SOAP response message list 2.33
typed messages using a non-contract services to access the message header [ServiceContract] public class StockService2 {[OperationContract] private Message GetPrice ( Message req) {string timeZone = OperationContext.Current.IncomingMessageHeaders.Ge tHeader (“TimeZone”, “http://EssentialWCF/”); string ticker = req.GetBody (); Message resp = Message. CreateMessage (req.Version, req.Headers.Action “Response”, timeZone “|” ticker “|” “94.85″); return resp;}} list 2.34 describes how a client adds a SOAP message head to the side that will be sent to the service untyped messages. First, create a message using CreateMessage, use the constructor to put the data message. Then a type of MessageHeader is created; in this case it is a string data into the message header by the constructor. Next, an untyped MessageHeader MessageHeader be created from the type of the last type of non-MessageHeader to be added to the message sent to the service.
untyped messages untyped operating lease allows the client and server almost in the SOAP message body can transmit any content, as long as the content of communication can be used to encode the binding stack. WSDL message content is absolutely transparent for the mercy of no XSD to define the data. Client and server use System.ServiceModel.Channels.Message class to create, read and write messages.
non-news type of contract does not use any property of a message to describe their contents. It is completely run-time code used to make the content meaningful. This is the direct use of XML message set is very useful information, in which case you may want to while away completely lost in the WCF code using the Document Object Model programming (Document Object Model). Used in conjunction with non-service operation type of the message receiver and returns the information set of XML message types.
2.33 shows a list of non-realization of a type of the message header in the operation and then read data from the service contract. Note that the message header data, timeZone, is a line of code access.

messages sent to a contract describes the services and services received from a SOAP message structure, and allows you to detect and control the SOAP message headers and body in most of the details. And data contract allows use of XML metadata definition (XSD) standard for interoperability between systems, the message contract that enables any system to communicate via SOAP interoperability.


If you are using typed messages, WCF 2.28 through the list described in [MessageHeader] attribute to explicitly support it. If you use an untyped messages, however, you need to explicitly add an untyped message header.
2.28 shows a list of typed message contract, StockPrice. the message header contains a simple type, DateTime, the message body contains a complex type, PriceDetails. PriceDetails class must be serializable, or by using a [ DataContract] attribute, or, as here shown, use the [Serializable] attribute. This example is only a message header and a message body, but can have a lot of message header and message body.
If you want to leave the operation signatures to the transmission of information, then transmit the message through the SOAP message header is useful. For example, session, or related information can be passed in the message header, rather than to add additional operating parameters or add the data itself as an attribute of information. Another example is the safe, when you want to implement a custom security protocol (bypassing the WS-Security) and the custom SOAP header to pass the certificate or certificates. The third example, is about the safe, you may want to sign, encrypt some or all of the local header of the SOAP message header to sign and encrypt. All of these situations can be handled using a message contract. The disadvantage of this technique is the client and server must be added manually from the SOAP message headers and collect information, rather than operating lease contracts and associated data serialization classes for you to achieve.
Note service operation to receive and send message type. When using a message contract, the input and output parameters must be marked [MessageContract] property of the message. More specifically, the operation must include a precise input parameter and must return to determine the unique result, they are news, because the request from the operator to send out and receive a reply message to directly map their SOAP said. Additional message-based programming and parameter-based programming can not be confused, so you can not put a data contract as an operation input parameters and returns a message that it contracts as a result of, or identify a message as an operating lease and the input parameters it returns a data contract as a result. You can tell the type of message is mixed and non-typed messages, but not the message contract and data contract. In the end you generate the WSDL from the service contract and data contracts to mix the message will cause a runtime error.
2.32 shows the list returned by the server to the list of 2.31 in the SOAP message request. Note that the operation of the SOAP message header in the back there is a “Response”, SOAP message body is a non-XML format string.

In some scenarios, the design stage you may not know the client and server transmit the message structure. For example, the information will be incorporated into the message itself, such as in the design stage to determine the routing information and services operations. Or the client and service side of a software (or hardware) level to operate the SOAP message and look forward to a special data format. Of these cases, the non-contract type of operation will be very useful.
2.35 client list into the message header to an untyped message
corresponding, you can use svcutil.exe / messageContract or / mc option. This makes the svcutil.exe to generate proxy with a public method to receive typed messages, so clients can call for the method of approach. If you are using without / mc option of svcutil.exe way or you did not use the add service reference is always selected to generate a message contract will be used to receive parameter method to generate a public agency, and will be called message-based operating within . In any case, the line will send the same XML message. 2.28 to define a typed list of news contract namespace EssentialWCF {[Serializable] public class PriceDetails {public string Ticker; public double Amount;} [MessageContract] public class StockPrice {[MessageHeader] public DateTime CurrentTime; [MessageBodyMember] public PriceDetails Price;} [ MessageContract] public class StockPriceReq {[MessageBodyMember] public string Ticker;} [ServiceContract] public interface IStockService {[OperationContract] StockPrice GetPrice (StockPriceReq req);} public class StockService: IStockService {# region IStockService Members public StockPrice GetPrice (StockPriceReq req) { StockPrice resp = new StockPrice (); resp.Price = new PriceDetails (); resp.Price.Ticker = req.Ticker; resp.Price.Amount = 94.85; return resp;} # endregion}} list 2.29 shows when a SOAP message returned from the server to the client when the transmission of XML messages. Note [MessageHeader] elements, CurrentTime, in the SOAP message header and [MessageBodyMember] elements, Price, in the SOAP message body. 2.29 to generate a list of typed messages using the SOAP Response
contract list 2.30 definitions and implementation of non-news type of contract [ServiceContract (Namespace = "http://EssentialWCF")] public class StockService2 {[OperationContract] private Message GetPrice ( Message req) {string ticker = req.GetBody (); Message resp = Message.CreateMessage (req.Version, req.Headers.Action “Response”, ticker “|” “94.85″); return res CITIC Bank that pits father, buried by an annual fee to upgrade CITIC credit card trap p;}} code similar to the services the client-side code, use CreateMessage to create a message, use the appropriate version to match the binding, then use GetBody method to read the server the returned results. Note CreateMessage method uses three parameters: version, operating, and string messages. When you create a message, the message version must be used to communicate with the server bindings compatible MessageVersion property through the channel definition. Operations, such as http://EssentialWCF/StockService/GetPrice, are SOAP and WCF based server used to forward the message to the appropriate action. 2.31 shows the list with 2.30 in the service code list to communicate with the client code.

In these cases, you must tell WCF which should appear in the WSDL contract contains the class. This is accomplished using KnownTypes. It can be accomplished in four ways: by adding a KnownType attribute to [DataContract], by [ServiceContract] or [OperationContract] attribute in the configuration file by adding a reference to it and its assembly, or by When generating the WSDL definition of it.
class hierarchy defined in the list
2.17, the three elements from the Price class and a subclass composition. StockPrice, inherited from Price. Namespace applied to the two classes so they perfectly legal in XML by the name of. Each element retains its own namespace.
2010 年 10 月 19 日
First, the type of reference you can have moved from code to the configuration file, in the service configuration file system.runtime.serialization some type of information has been added. Taking into account class inheritance, you need to add reference to the base class and add KnownType reference to a derived class. This list shows 2.22 when EssentialWCF.Price is the base class and EssentialWCF.StockPrice and EssentialWCF.MetalPrice is derived class, StockService the boarding of these types of DLL.
Give an example of class inheritance. If a sequence of the derived class to reach a look forward to receiving a sequence of the base class endpoint, WCF does not know how to deserialize the derived class because it is not part of the contract. Another example is a hashtable class, storage class as the other elements of their own. WSDl hashtable class will be defined, but not so the class is stored in the internal hashtable.
2.23 configuration file defines the list of KnownType Credit Card Bank did not open the card annual fee reminder is reproduced Price, StockService, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null “> in the contract to determine the derived class of the most common method is to generate it at runtime, which can be exposed by the WCF hooks to complete. [KnownType] and [ServiceKnownType] constructor accept two characters string parameter is the string serialization or deserialization returns a list of known types of method name, if you use one of the original data container, the container or you can find the database at run-time type information and exposure to them. the list 2.23 shows a simple implementation, showing the type name is hardcoded into the GetKnownTypes method instead of being dragged into the container from the outside. 2.23 runtime code list defined KnownType [DataContract (Namespace = "http://EssentialWCF/ ")] [KnownType (typeof (StockPrice))] [KnownType (typeof (MetalPrice))] public class Price {[DataMember] public double CurrentPrice; [DataMember] public DateTime CurrentTime; [DataMember] public string Currency; static Type [] GetKnownTypes () {return new Type [] {typeof (StockPrice), typeof (MetalPrice)};}} [DataContract (Namespace = "http://EssentialWCF/")] public class StockPrice: Price {[DataMember] public string Ticker ; [DataMember] public long DailyVolume;} [DataContract (Namespace = "http://EssentialWCF/")] public class MetalPrice: Price {[DataMember] public string Meta; [DataMember] public string Quality;}
list 2.20 shows the definition of base class data contract, Price, there are two classes derived from the base class, StockPrice and MetalPrice. Note that the data contractual [KnownType] attribute, which tells WCF contract when exposed to include when the XSD StockPrice and MetalPrice said. The list also includes service implementation. GetPrice operation is polymorphic, and its return value type can be StockPrice or MetalPrice, depending on which operation is requested by the client proxy code calls GetPrice structure must be cast into need to access the return value type classes, and a list defined in the contract data 2.20 KnownType using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization; using System.ServiceModel; namespace EssentialWCF {[DataContract (Namespace = "http://EssentialWCF/")] [KnownType (typeof (StockPrice))] [KnownType (typeof (MetalPrice))] public class Price {[DataMember] public double CurrentPrice; [DataMember] public DateTime CurrentTime; [DataMember] public string Currency;} [DataContract (Namespace = "http://EssentialWCF/")] public class StockPrice: Price {[DataMember] public string Ticker; [DataMember] public long DailyVolume;} [DataContract ( Namespace = "http://EssentialWCF/")] public class MetalPrice: Price {[DataMember] public string Meta; [DataMember] public string Quality;} [ServiceBehavior (Namespace = "http://EssentialWCF/Fi nanceService /") ] [ServiceContract (Namespace = "http://EssentialWCF/Fi nanceService /")] public class StockService {[OperationContract] public Price GetPrice (string id, string type) {if (type.Contains (“Stock”)) {StockPrice s = new StockPrice (); s.Ticker = id; s.DailyVolume = 45000000; s.CurrentPrice = 94.15; s.CurrentTime = DateTime.Now; s.Currency = “RMB”; return s;} if (type.Contains (“Metal”)) {MetalPrice g = new MetalPrice (); g.Meta = id; g.Quality = “0 .. 999″; g.CurrentPrice = 785.00; g.CurrentTime = DateTime.Now; g.Currency = “RMB”; return g;} return new Price ();}}} Accordingly, you can use the [ServiceKnownType] property defined in OperationContract level KnownType. When KnownTypes is defined in the operating level, the derived class can only have been defined know the type of operation used in other words, not all the operations a service can use the derived class. list 2.21 shows the use of [ServiceKnownType] code fragments in this case, when a message from the server returns a GetPrice client can call methods, deserializer will create a StockPrice or MetalPrice object, but when the client can only be passed when calling SetPrice a Price object, rather than a StockPrice or MetalPrice object, because the serializer does not know in XML how to express these derived types.
complex type in the code to the general form of the class implementation. complicated further by increasing the special structure of the class inheritance relationship defined in this way, a common type such as “price” can be derived for a more specific type, such as “stock price” or “house price”. WCF supports the WSDL through the appropriate representation of the class inheritance relationship between the class structure and the XML serialization and deserialization are also from each Remove the attribute class and add to a collection.
list defined in the contract operations 2.21 KnownType [ServiceBehavior (Namespace = "http://EssentialWCF/Fi nanceService /")] [ServiceContract (Namespace = "http:/ / EssentialWCF / Fi nanceService / ")] public class StockService {[ServiceKnownType (typeof (StockService))] [ServiceKnownType (typeof (MetalPrice))] [OperationContract] public Price GetPrice (string id, string type) {if (type.Contains (“Stock”)) {StockPrice s = new StockPrice (); s.Ticker = id; s.DailyVolume = 45000000; s.CurrentPrice = 94.15; s.CurrentTime = DateTime.Now; s.Currency = “RMB”; return s;} if (type.Contains (“Metal”)) {MetalPrice g = new MetalPrice (); g.Meta = id; g.Quality = “0 .. 999″; g.CurrentPrice = 785.00; g.CurrentTime = DateTime.Now; g.Currency = “RMB”; return g;} return new Price ();}} both in the data contract or service contract layer layer, defined in the code known disadvantage is that you need to type at compile time into the derived class to know if a new type is added, you need to recompile the code, which you can use two methods to solve.
If the data types to meet any of the conditions described earlier, then they will be exposed in the WSDL out there may be some extra, of course, you may want to force a type included in the WSDL contract
2.17 using data contract defines a list of the class hierarchy using System; using System.Collections.Generic; using System.Linq ; using System.Text; using System.Runtime.Serialization; namespace Stock {[DataContract (Namespace = "http://EssentialWCF/Price/")] public class Price {[DataMember] public double CurrentPrice; [DataMember] public DateTime CurrentTime ; [DataMember] public string Currency;} [DataContract (Namespace = "http://EssentialWCF/StockPrice")] public class StockPrice: Price {[DataMember] public string Ticker; [DataMember] public long DailyVolume; [DataMember] public double DailyChange;}} to generate these two XML metadata is used to support the basis for the list to display the relationship 2.18 First Price XML metadata display, followed by the show StockPrice XML metadata import Price StockPrice attention metadata. Note that in XSD, all elements are defined with minOccurs = 0, because they are not in the code using [isRequired = true] to define the attributes and a list 2.18 XML metadata as defined in the class hierarchy StockPrice type of a serialized SOAP message body is displayed in the list 2.19 Note Price and StockPrice namespace entirely through the SOAP message body be moved from the code list list 2.17 2.18 in the XML metadata data, and a list 2.19 SOAP message body serialization class hierarchy Dollars 100 2006-12-13T21: 18: 51.313-05:00 0.012345 450000 < / a: DailyVolume> msft KnownTypes exposed in WSDL using additional types

As a reference, a female friend to express “I period of the” argument is: I e got my period now. And, “she miscarried,” saying it is: She lost the baby.
Place is the situation of synonyms But we still have to pay attention to the clear distinction between the two.
“she was pregnant.” can be expressed as; She is expecting now. it can be said: She is pregnant now. expression “term, and soon to give birth a” is: My time is near. “She has been pregnant nine months, “and can say: She is into the ninth month. and” pregnancy reaction “argument, is morning sickness, for example: My life has morning sickness. (my wife have pregnancy reaction.)
have story, a few years ago a couple living in a foreign country, but is not proficient in English. Suddenly the wife started labor pains, quickly call 911 for help, when asked what other things when her husband said in broken English: My baby is coming. He wanted to express “my kids are out,” but the other party has not understand what he meant. In fact, in this case the correct expression should be used is shown in the title: My wife has begun to have labor pains.
It not my place to help you. To help you, had not my duty.
this, ah, just to be desperate.
how much they charge you?
B: Well, I in a no-win situation now.
really? I sorry.
cosigner is “co-signer.” For example: Do you think I can get a loan without a cosigner? (No co-signer if I can apply for loans?) Where the loan term in addition to a “loan” means, but also includes “loans, loan” means .
title of this chapter shows the sentence “I l show you …” is mainly used to express “I l give you a look at …” means. If you want to express. “Lets you know how to do …”, you can use the sentence: I l show you how to do (infinitive). For example: I l show you how to get there. (I told you how to get there.)
Recent business how?
he thought he was the big names do.
place the word also can express “identity, status, qualifications” means. So the sentence “It not my place to infinitive” is the expression “I did not do … … of qualification” means. For example:
Remember, the classic English song “Yesterday” in such lyrics:
no-win situation refers to not win the case, expressing the speaker despair, give up hope of the state. Expression of consent there “catch-22 situation” and “I in a rock and hard place.”
It not your place to say that. So that you are not eligible.
there, “He always prides himself on his knowledge.” means “He often show off their knowledge.” “He thinks he is really great.” meaning is “He was very tall.”
A: How much do they charge you?
look at one case using the choice of the expression, “I have no choice but to love her.” means “in addition to love her I had no choice.” A: How your business nowadays?
Expression with the use of contrast is the “have no choice but to do sth.” (In addition to … … have no choice). For example: We have no choice but to meet a buyer. (We have no choice except see procurement).
2010 年 12 月 21 日
good idea. labor not only the expression “labor, hard work” and the meaning, but also “the pains of childbirth” means. So be in labor expression means “is birth.” In addition, delivery in addition to the “delivery” means, it can also mean “birth, birth”, so the delivery room is the “delivery room.”
confiscation of money, because still under warranty.
“I in a rock and hard place.” is said, “I was behind a rock in front of cliffs”, or “dilemma.”
Yes, ah, when to give him powerful look.
B: There is no charge because it still under warranty.
B: Yeah. I l show him what whenever.
It not my place to answer the question. I am not qualified to answer this the problem.
Oh? Really? Really nice!
in the hospital, if you want to ask, “What is the expected period of time”, you can say: When are you expecting? or items can be due dat machine defecate annual fee credit card consumers of the new rules e expressed as “When is your baby due date? “
Apart from using the guarantee to represent the” guarantee “, we have another way to express this meaning, that is: warranty.
” It not my place to infinitive “is the key sentence, should practice more.
expression in the same position, we can say: We e all in the same boat. means “just us sitting in the same boat.”
A: Oh, really? Sounds great!
warranty with “warranty, the warranty period” means, so “It comes with a full one-year warranty on everything.” means “all the goods warranty for one year. ”
A: Really? I sorry to hear that.
“under warranty”, that is: under warranty. We say: It comes with a full warranty. means “lifetime warranty this product . ”
a drama had been such a line:
“Do not blame me”, to express these words, we can say: Don pass the buck to me. sentence “pass the buck to sb. “that is the expression” passing the buck to … “means.
“You do not think they great,” can pretend expressed as: Don pretend you are somebody. “Do not install air” can be expressed as: Don show off. and “Do not install very busy.” you can say: Don pretend you e busy everyday.
I need a place to hide away. I need a place to hide.
A: That a good idea.
guarantee that we are already familiar with the term to express “guarantee” means, so “good, I promise” can be said: It guaranteed. athletes before the start of the game get the “margin” is the guarantee money.
This sentence can also be briefly expressed as: “My wife is in labor.” or “My wife is having a baby.”
and “both sides responsibility, “you can say: It takes two to tango. – a tango, two hand to speak out ah! A: He acts like a great man.
Title of the sentence as shown: “I l show you” followed by a word what, literally, this sentence means: you take a look at a material / something. However, the real meaning of this sentence is: I will give you some powerful look.
title situation with the word “state, condition, location,” and the meaning. When the expression “state” this meaning when used to express “the state of things.”
at a / the crossroads, meaning “(of life or development) at a critical juncture; in a pinch.” So if you say: I at the crossroads. Which means “I faced an important choice.” On “at a / the crossroads”, we need to master the sentence “at the crossroads to do sth.”
As a reference, “He is to blame for it.” Means “this he should be criticized. “” I stand behind my job. “The meaning is” I am responsible for my work. “
Do they guarantee their merchandise? they guarantee product warranty?
If someone arrogant, so that you are angry, we can say: He got an attitude. (He thought he was.) where the attitude is the meaning of “attitude, posture.” In addition, “He is so stick up.” This sentence is the expression commonly used in the film, “he too proud” means.

ogtzuq