- 浏览: 72302 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
z169351998:
...
StringOfArray in web service proxy -
z169351998:
撒大大 [size=x-small][/size]
StringOfArray in web service proxy -
z169351998:
引用[url][/url][flash=200,2 ...
StringOfArray in web service proxy -
huhu_long:
补充1:在二叉树遍历的时候,如果采取非递归的方式,则可以借助S ...
栈的一些应用 -
huhu_long:
简单说,取第一个作为参考pivot值,while(low< ...
快速排序
Serialize order for data members of the data contract
1. members without explicitly set the order value, and the order is the same with the alpha of each data member, for example:
2. members with order value, sort with the order value ASC, same order value order by alpha of the data member, same with #1
3. member without [DataMember] tag won't be serialized.
-------------------------------------------------- I'm the splitter ------------------------------------------
[MessageContract(IsWrapped=true)]
MessageContractAttribute can be applied to class and structure to define message structure. The default value of IsWrapped property is true. So in default, a SOAP message will use class name as the tag and all data members will be associated with it as the children tags. For instance
-------------------------------------------------- I'm the splitter ------------------------------------------
Three elements constitute and endpoint - ABCs of endpoints
A - Address, which is a URL identities the location of the service. An address contains fours parts, Scheme(http://, net.tcp://, this is not the same thing with protocal), Machine(www.google.com or localhost), Port(this is optional, preceded by a colon:), Path(this is possible when a service resides in a directory structure, e.g. webservice application hosted by IIS, http://localhost:8081/TestServiceApp/AccountService)
B - Binding, which determines how the service can be accessed. Such as the protocol used to access the service, the encoding method used to format the message contents, specify security requirement like SSL or SOAP message security. BTW, a service can have multiple endpoints, which means you can try different bindings and the client can use the best one available.
C - Contract, the fully qualified type name of the contract, e.g. MyNamespace.MyService
-------------------------------------------------- I'm the splitter ------------------------------------------
When sending a request to service, the dispatcher on the server will responsible for dispatching incoming request and call service type instance.
So if the operation is a One-Way operation, which means the dispatcher only need to dispatch this request, no need wait the response.
But if the request with large message and therefore time-consuming, it can invoke the operation asynchronously.
The conclusion is: it is make sense to invoke a One-Way operation asynchronously.
-------------------------------------------------- I'm the splitter ------------------------------------------
Begin_ & End_
As you know, if you select "Generate asynchronous operations" option when adding web service reference to project, we will get Begin_ & End_ operation pair together with operation itself. How to use it?
-------------------------------------------------- I'm the splitter ------------------------------------------
3 ways to create proxy instance
-------------------------------------------------- I'm the splitter ------------------------------------------
4 steps to use tracing in WCF
- Config WCF to generate trace data
- Set trace level
- Config trace listener (e.g. where to put the log? c:\aaa.svclog)
- Enable message loging
-------------------------------------------------- I'm the splitter ------------------------------------------
When the quota for logging messages is reached, WCF generates one additional message to indicate that the quota has been reached, so the actual number of log entries will be the specified quota plus 1. For example:
<system.serviceModel>
<diagnostics>
<messageLogging logentrieMessage="true"
logMalformedMessage="false"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="false"
maxMessagesToLog="1000"
maxSizeOfMessageToLog="2000"
</diagnostics>
</system.serviceModel>
So, according to the desc above, the maximum number of WCF messages that will appear in the trace log should be 1000 + 1 = 1001
-------------------------------------------------- I'm the splitter ------------------------------------------
Adding Message Inspectors to the Pipeline
1. Create Behavior
a) public class YourCustomBehavior : IEndpointBehavior
b) create inspector, assume your inspector named "TestInspector", which implements both "IClientInspector" and "IDispatchInspector" interfaces
c) add inspector in methods "ApplyClientBehavior" and "ApplyDispatchBehavior" in YourCustomBehavior class, like below:
d) now you have a behavior, it needs to be added to a behavior extension. Like below, the behavior extension extends from BehaviorExtensionElement class
e) refine your config file
P.S, there is alternative way to apply customer behavior to pipeline
-------------------------------------------------- I'm the splitter ------------------------------------------
Transport-Level Security
Below bindings are support transport-level security
Message-Level Security
Below bindings are support message-level security
-------------------------------------------------- I'm the splitter ------------------------------------------
1. members without explicitly set the order value, and the order is the same with the alpha of each data member, for example:
[DataMember(IsRequired = false] public string Country; should before [DataMember(IsRequired = false] public string Name;
2. members with order value, sort with the order value ASC, same order value order by alpha of the data member, same with #1
3. member without [DataMember] tag won't be serialized.
-------------------------------------------------- I'm the splitter ------------------------------------------
[MessageContract(IsWrapped=true)]
MessageContractAttribute can be applied to class and structure to define message structure. The default value of IsWrapped property is true. So in default, a SOAP message will use class name as the tag and all data members will be associated with it as the children tags. For instance
[DataContract] public class TestClass { [DataMember] public string Name; } then the SOAP likes ... <TestClass> <Name>...</Name> </TestClass> ... if IsWrapped = false, SOAP likes ... <Name>...</Name> ...
-------------------------------------------------- I'm the splitter ------------------------------------------
Three elements constitute and endpoint - ABCs of endpoints
A - Address, which is a URL identities the location of the service. An address contains fours parts, Scheme(http://, net.tcp://, this is not the same thing with protocal), Machine(www.google.com or localhost), Port(this is optional, preceded by a colon:), Path(this is possible when a service resides in a directory structure, e.g. webservice application hosted by IIS, http://localhost:8081/TestServiceApp/AccountService)
B - Binding, which determines how the service can be accessed. Such as the protocol used to access the service, the encoding method used to format the message contents, specify security requirement like SSL or SOAP message security. BTW, a service can have multiple endpoints, which means you can try different bindings and the client can use the best one available.
C - Contract, the fully qualified type name of the contract, e.g. MyNamespace.MyService
-------------------------------------------------- I'm the splitter ------------------------------------------
When sending a request to service, the dispatcher on the server will responsible for dispatching incoming request and call service type instance.
So if the operation is a One-Way operation, which means the dispatcher only need to dispatch this request, no need wait the response.
But if the request with large message and therefore time-consuming, it can invoke the operation asynchronously.
The conclusion is: it is make sense to invoke a One-Way operation asynchronously.
-------------------------------------------------- I'm the splitter ------------------------------------------
Begin_ & End_
As you know, if you select "Generate asynchronous operations" option when adding web service reference to project, we will get Begin_ & End_ operation pair together with operation itself. How to use it?
Binding binding = new WSHttpBinding(); ChannelFactory factory = new ChannelFactory(binding, "http://localhost:8080/MyService.svc"); IMyServiceChannel proxy = factory.CreateChannel(); proxy.BeginMyOpertion(123, new AsyncCallBack(MyCallBack), proxy); // Other code logic...
private void MyCallBack(IAsynResult result) { IMyServiceChannel proxy = result.AsyncState as IMyServiceChannel; string value = proxy.EndMyOperation(result); // Other code logic... }
-------------------------------------------------- I'm the splitter ------------------------------------------
3 ways to create proxy instance
class Program { static void Main(string[] args) { // 1: Look for the endpoint configuration name to create proxy instance. Service1Client sc = new Service1Client("WSHttpBinding_IService1"); string resultValue = sc.GetData(123); // 2: Use endpoint uri and binding to create proxy instance. EndpointAddress ea = new EndpointAddress("http://localhost:45504/Service1.svc"); Service1Client codeProxy = new Service1Client(new WSHttpBinding(), ea); string value = codeProxy.GetData(123); // 3: Use channel factory to create dynamic proxy instance via binding and endpoint uri ChannelFactory<IService1Channel> factory = new ChannelFactory<IService1Channel>(new WSHttpBinding(), "http://localhost:45504/Service1.svc"); IService1Channel proxy = factory.CreateChannel(); proxy.BeginGetData(123, new AsyncCallback(HandleCallBack), proxy); System.Console.ReadLine(); } static void HandleCallBack(IAsyncResult result) { IService1Channel client = result.AsyncState as IService1Channel; string value = client.EndGetData(result); System.Console.WriteLine("done"); } }
-------------------------------------------------- I'm the splitter ------------------------------------------
4 steps to use tracing in WCF
- Config WCF to generate trace data
- Set trace level
- Config trace listener (e.g. where to put the log? c:\aaa.svclog)
- Enable message loging
-------------------------------------------------- I'm the splitter ------------------------------------------
When the quota for logging messages is reached, WCF generates one additional message to indicate that the quota has been reached, so the actual number of log entries will be the specified quota plus 1. For example:
<system.serviceModel>
<diagnostics>
<messageLogging logentrieMessage="true"
logMalformedMessage="false"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="false"
maxMessagesToLog="1000"
maxSizeOfMessageToLog="2000"
</diagnostics>
</system.serviceModel>
So, according to the desc above, the maximum number of WCF messages that will appear in the trace log should be 1000 + 1 = 1001
-------------------------------------------------- I'm the splitter ------------------------------------------
Adding Message Inspectors to the Pipeline
1. Create Behavior
a) public class YourCustomBehavior : IEndpointBehavior
b) create inspector, assume your inspector named "TestInspector", which implements both "IClientInspector" and "IDispatchInspector" interfaces
c) add inspector in methods "ApplyClientBehavior" and "ApplyDispatchBehavior" in YourCustomBehavior class, like below:
// to add inspection to the client side. public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { TestInspector inspector = new TestInspector(); clientRuntime.MessageInspectors.Add(inspector); } // to add inspection to the server side. public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { TestInspector inspector = new TestInspector(); endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector); }
d) now you have a behavior, it needs to be added to a behavior extension. Like below, the behavior extension extends from BehaviorExtensionElement class
public class YourTestBehaviorExtensionElement : BehaviorExtensionElement { public override Type BehaviorType { return typeof(YourCustomBehavior); } public override object CreateBehavior { return new YourCustomBehavior(); } }
e) refine your config file
<system.serviceModel> <behaviors> <endpointBehaviors> <behavior name="YourCustomBehavior"> [b]<messageLogger />[/b] </behavior> </endpointBehaviors> </behaviors> <extensions> <behaviorExtensions> <add name="messageLogger" type="your.assembly.namespace.typename, assembly.name, version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> </behaviorExtensions> </extensions> </system.serviceModel>
P.S, there is alternative way to apply customer behavior to pipeline
ServiceProxy proxy = new ServiceProxy(); proxy.Endpoint.Behaviors.Add(new YourCustomBehavior());
-------------------------------------------------- I'm the splitter ------------------------------------------
Transport-Level Security
Below bindings are support transport-level security
- basicHttpBinding
- basicHttpContextBinding
- wsHttpBinding
- netTcpBinding
- netTcpContextBinding
- netNamedPipeBing
- msmqIntegrationBinding
- netMsmqBinding
Message-Level Security
Below bindings are support message-level security
- basicHttpBinding
- basicHttpContextBinding
- wsHttpBinding
- netTcpBinding
- netTcpContextBinding
- netMsmqBinding
- wsDualHttpBinding
-------------------------------------------------- I'm the splitter ------------------------------------------
发表评论
-
LINQ to SQL Debug Visualizer
2013-03-13 03:42 683http://weblogs.asp.net/scottgu/ ... -
Oracle.DataAccess.dll
2012-10-03 12:45 962Oracle.DataAccess.dll will prev ... -
Timezone
2012-09-29 06:56 751How stupid I was yesterday.... ... -
StringOfArray in web service proxy
2012-09-29 00:09 1379Sometimes we may need reference ... -
Set attributes at runtime
2012-09-26 04:12 793Changing a property's attribute ... -
Google Map Directions
2012-09-15 03:20 1205First time try google map relat ... -
Uri.TryCreate vs Regex
2012-09-08 02:56 966Today, Ken Crismon reviewed my ... -
Parallel.ForEach
2012-08-16 06:17 831Parallel calculation is brought ... -
C# Outlook Addin Error
2012-06-06 15:37 882Error description: 引用 Not load ... -
Outlook Addin Setup Project Configuration
2012-06-01 16:39 0http://msdn.microsoft.com/en-us ... -
.net excel
2012-05-28 09:44 0Copy excel row and insert, merg ... -
MCTS Self-Paced Training Kit (Exam 70-516)
2012-05-11 16:05 0DataTable vs DataSet -
drop down list auto post back
2012-04-16 22:54 807If we set DDL's AutoPostBack pr ... -
The download of the specified resource has failed.
2011-09-05 14:02 883Recently, "The download of ... -
Type.GetType()
2011-08-01 15:15 866// .net code private Type GetT ...
相关推荐
《MCTS Self-Paced Training Kit (Exam 70-503) Microsoft .NET Framework 3.5》是一本专为准备微软认证技术专家(MCTS)考试70-503而设计的自学教材。这本书全面覆盖了.NET Framework 3.5中的核心技术和关键概念,...
《MCTS Self-Paced Training Kit (Exam 70-529): .NET Framework 2.0 分布式应用开发》是一本专为准备Microsoft Certified Technology Specialist(MCTS)70-529考试的读者设计的自学教材。这本书旨在帮助IT专业人士...
《MCTS Self-Paced Training Kit Exam 70-536-2E》是一本针对Microsoft Certified Technology Specialist(MCTS)认证考试70-536的自学教材,旨在帮助学习者深入理解并掌握.NET Framework 2.0的核心概念和技术。...
### MCTS Self-Paced Training Kit Exam 70-515: TS: Web Applications Development with Microsoft .NET Framework 4 #### 考试概述与目标 考试 70-515 主要针对的是希望获得 Microsoft Certified Technology ...
#### 一、MCTS 自学培训包(考试 70-515):使用 Microsoft .NET Framework 4 开发 Web 应用程序 本自学培训包旨在帮助考生准备 Microsoft 认证技术专家 (MCTS) 考试 70-515。该考试重点考察考生使用 Microsoft ...
这个压缩包包含了两个文件,一个是详细的学习指南PDF,名为“Microsoft.Press.MCTS.Self.Paced.Training.Kit.Exam.70-515.Dec.2010.pdf”,另一个是“Readme.png”,通常包含有关学习资源的简短说明或注意事项。...
通过《MCTS Self-Paced Training Kit (Exam 70-562).pdf》的学习,考生将获得实践项目的经验,同时通过模拟试题和复习资料巩固理论知识。这本书涵盖了所有考试的重点,是准备MCTS 70-562考试的理想资源。通过深入...