Saturday, September 15, 2012

70-513 WCF Study Notes


Skill measured in the exam

http://www.microsoft.com/learning/en/us/exam.aspx?id=70-513

This is my raw notes I made while studying for the exam.

HOSTING

Its valid to not specify any end-points. Adding base addresses will infer binding, contract is inferred by service name.

DISCOVERY

To discover a service:
Create one FindCriteria object for each iterface and set their Duration properties to two seconds. Loop for 30 seconds total and invoke their Find methods.
To implement a "logger" that recieves service start and stop announcments use the AnnouncementService class not the AnnouncementClient class.


RSS CONSUMPTION FROM A CLIENT

SyndicationFeed has an Items property : SyndicationItem
TextSyndicationContent : SyndicationItem
+Text : string


CUSTOM BINDING - DEFINING THE ORDER OF ELEMENTS (TRSMTET)

Transactions
Reliability
Security
Message Patterns
Transport upgrades/helpers
Encoding
Transport

MESSAGE QUEUEING

To deliver to Dead Letter queue use Reject enum value for receiveErrorHandling.
Poison messages use the Move, or Drop
Fault is the default value. (Throws an exception).
Address of dead letter queue: net.msmq://localhost/system$;DeadLetter


REST JSON SERVICES

When using WebGet attrib must use a SVC file <%ServiceHost Service="TestService" Factory="System.ServiceModel.ActivationWebServiceHostFactory" %>
or the WebHttpBehaviour on the service.
Use webHttpBinding for Pox/Json and general WCF use from javascript.
Use enableWebScript for Ms AJAX usage.


ROUTING SERVICES

ISimplexDatagramRouter = Reflects a one way message exchange.
ISimplexSessionRouter  = Reflects a one way message exchange with a session aware channel.
IRequestReplyRouter    = Reflects a request-reply message exchange.
IDuplexSessionRouter   = Reflects a  duplex communication using a callback contract.
Cannot mix message patterns when routing.  For contracts that do, use IDuplexSessionRouter and use callbacks to route the responses.


PROXY USAGE

Closing/Disposing a failed proxy might throw. Rather use .Abort in the exception handler or finalise block.
Any Reuse of a closed proxy will result in ObjectDisposedException
Proxy's should derive from ClientBase<T>, T = ServiceContract.


SERVICE EXCEPTIONS

Use serviceDebug element in web.config
[FaultContract(typeof(FaultException<Order>))] is valid but received by client as FaultException.
[FaultContract(typeof(ErrorInfo))              is best, received by client as FaultException<ErrorInfo>.


PERFORMANCE MONITORING, LOGGING AND AUDTING

Use serviceSecurityAudit element in a behaviour to audit to event log.
setting <diagnostics performanceCounters="ServiceOnly"/> will only give service level counters (no endpoint or operation level counters are available).
EventLogs are added to the security log by default in IIS7+ or Application in IIS6.
Calls failed is talking about unhandled exceptions
Calls faulted is when FaultExceptions are thrown.
MessageLogging/Filters can contain operation level filters:
<add xmlns:addr="http://www.w3.org/2005/08/addressing">addr:Action[text()='http://namespaceOfService/IServiceContract/OperationNameResponse']</add>
Configuring Logging:
<diagnostics>
<messageLogging logEntireMessage="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"/>
<sources>
<source propagateActivity="true" name="System.ServiceModel" switchValue="Warning, ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener"/>
</listeners>
</source>
<sources>
</diagnostics>

mexHttpBinding is a valid binding. Useful when the same address is used for service call and metadata.


SECURITY

OperationContract has a protection level.
ServiceContract has a protection level that enforces a Minimum.
Message level security must be encrypted using a cert
Don't use SecurityAction.Assert only use .Demand.
Mulitple PrincipalPermission attributes allowed and are Or'ed.
wsHTTPBinding defaults to message security and client credential type Windows.

IMPERSONATION

TokenImpersontationLevel.Impersonation
Impersonates the user's credentials only on that service machine.
TokenImpersonationLevel.Delegatioin
Allows impersonation of the user's credentials on the service machine and other machines.
When ImpersonateCallerForAllServiceOperations is false Allowed results in no impersonation.
Required always results in impersonation.
ServiceSecurityAuditBehavior adds to windows event log in security section.
<machineSettings enableLoggingKnownPii="true"/> allows usernames and passwords to be logged in clear text in the WCF standard diagnostics logs. It is false by default.
You can implement custom message level security binding with TransportSecurityBindingElement.
Setting EstablishSecurityContext will not issue a token and require every call be re-authenticated.

CERTIFICATES

StoreName.My = Personal certs for logged in user
StoreName.Root = Trust Root CA's
StoreName.AuthRoot = Third party CA's


STREAMING

NetTcpBinding doesnt support message streaming with SessionMode=Required or with Reliable Sessions configured on.
Use MTOM Message Transmission Optimization Mechanism for streaming large files; its more efficient than binary.


CONTRACTS

SERVICE BEHAVIOR ATTRIBUTE
AutomaticSessionShutdown
ConcurrencyMode
ConfigurationName
IncludeExceptionDetailsInFaults
InstanceContextMode (PerSession Default)
Name
Namespace
ReleaseServiceInstanceOnTransactionComplete
TransactionAutoCompleteOnSessionClose
TransactionIsolationLevel
TransactionTimeout
UseSynchronisationContext

OPERATION BEHAVIOR ATTRIBUTE

Impersonation
RelaseInstanceMode
TransactionAutoComplete
TransactionScopeRequired

TRANSACTION FLOW ATTRIBUTE 

Used on an Operation Contract (Allows|Mandatory|NotAllowed)

ORDER BEHAVIOURS ARE EVAL'D

Most specific to most general
Contract, Operation, Endpoint, Service
Reliability should be turned on for Http bindings.


MESSAGE CLASS

A message instance can only be accessed or written to once.
To eliminate duplicate xmlns in Message contracts, embed a datacontract as the sole messageBodyMember and declare the namespace on the datacontract.
To read a message Use CreateBufferedCopy method of the Message class, use CreateMethod of the MessageBuffer class to make a copy.

TOOLS

SvcUtil.exe
Generate a client side proxy from service metadata.
Generate metadata from services
WCFTestClient.exe
Edit Client configuration
Invoke service methods
WSDL.exe
Generate a client side proxy from service metadata.

No comments:

Post a Comment