DSPy a system for AI to Write Prompts and Do Fine Tuning
10 Tricks and Tips for WCF
1. Top 10 Tricks & Tips for WCF
Barry Dorrans
http://idunno.org
2. About the Speaker
(the ego slide)
MVP – Visual Tools, Security
barryd@idunno.org
3. Agenda
1) The test harnesses
2) Don’t use Using
3) It’s all your fault
4) Migrating an ASMX
5) Message Inspectors
6) Custom Authentication
7) Port sharing
8) Callbacks
9) Logging
10) RESTful services
4. What is WCF?
Indigo
Replaces Web Services, WSE &
Remoting
Interoperability
17. Faults the right way
In Contract Code
[ServiceContract]
public interface IService1
{
[OperationContract]
[FaultContract(typeof(NegativeNumberFault))]
string GetDataWithFault(int value);
}
[DataContract]
public class NegativeNumberFault
{
}
In Service Code
throw new FaultException<NegativeNumberFault>(
new NegativeNumberFault(),
new FaultReason(quot;value was negativequot;));
In Client Code
try
{
....
}
catch (FaultException<NegativeNumberFault>)
{
....
}
19. Migrating an ASMX
1. Change the protocol binding to
basicHttpBinding
2. Match your namespaces
[ServiceContract(Namespace=quot;http:/tempuri.org/quot;)]
3. Match your actions
[OperationContract(Action = quot;http://tempuri.org/HelloWorldquot;)]
4. Match your message names (if you use them)
[OperationContract(Action = quot;http://tempuri.org/HelloWorldquot;,
Name = quot;MyMessageNamequot;)]
5. Change the serializer to use XmlSerializer
[XmlSerializerAttribute]
public class MyService
20. Migrating an ASMX
6. Make WCF answer ASMX
<buildProviders>
<remove extension=quot;.asmxquot;/>
<add extension=quot;.asmxquot;
type=quot;System.ServiceModel.Activation.ServiceBuildProvider,
System.ServiceModel, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089quot;/>
</buildProviders>
22. Message Inspectors
1. Can be client or server side
2. Messages can be modified – but you must copy
the message then replace it.
3. Apply the custom behaviour via config or via
an attribute.
24. Custom Authentication
1. Reference System.IdentityModel and
System.IdentityModel.Selectors
2. Implement a UsernamePasswordValidator
3. Plug it in via config
26. Port Sharing
1. Vista / Windows 2008 –
netsh http add urlacl
url=http://+:port/url/
user=Everyone
2. XP / Windows 2003 (Support Tools)–
httpcfg set urlacl
/u http://*:80/url/
/a D:(A;;GX;;;NS)
3. XP does not port share with IIS.
28. Callbacks
1. Publish / Subscribe model works best
2. Declare a callback interface
interface IMessageCallback
{
[OperationContract(IsOneWay = true)]
void OnMessageAdded(string message, DateTime timestamp);
}
3. Add the callback to the service contract.
[ServiceContract(CallbackContract = typeof(IMessageCallback))]
4. Implement callback interface on client.