WCF testing notes
Health Monitoring:
https://blogs.msdn.microsoft.com/rahulso/2006/04/13/health-monitoring-for-applications-lifetime-related-events-in-asp-net-2-0/Ignore Security:
https://stackoverflow.com/questions/703272/could-not-establish-trust-relationship-for-ssl-tls-secure-channel-soapIntercept WCF response/request:
DataContractSerializer Reference:
例子:
var binding = new WSHttpSecurity();
var endpoint = new EndpointAddress("https://XXXXXXXXXXXX.svc");
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
var channelFactory = new ChannelFactory<IXXXService>(new WSHttpBinding(SecurityMode.Transport, false), endpoint);
var inspector = new InspectorBehavior();
channelFactory.Endpoint.Behaviors.Add(inspector);
XXXXX svc = channelFactory.CreateChannel();
var aaa = inspector.LastRequestXML;
var bbb = inspector.LastResponseXML;
----------------------------------
public class InspectorBehavior : IEndpointBehavior
{
public string LastRequestXML
{
get
{
return myMessageInspector.LastRequestXML;
}
}
public string LastResponseXML
{
get
{
return myMessageInspector.LastResponseXML;
}
}
private MyMessageInspector myMessageInspector = new MyMessageInspector();
public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
}
public void Validate(ServiceEndpoint endpoint)
{
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
clientRuntime.MessageInspectors.Add(myMessageInspector);
}
}
public class MyMessageInspector : IClientMessageInspector
{
public string LastRequestXML
{
get; private set;
}
public string LastResponseXML
{
get; private set;
}
public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
LastResponseXML = reply.ToString();
}
public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
{
LastRequestXML = request.ToString();
return request;
}
}
--------------------------
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
internal static XXXXXXXXXXX CreateChannelFactory(string url)
{
WSHttpBinding wsHttpBinding = new WSHttpBinding();
wsHttpBinding.Security.Mode = SecurityMode.Transport;
wsHttpBinding.SendTimeout = new TimeSpan(0, 0, 1);
EndpointAddress endpointAddress = new EndpointAddress(url);
var channelFactory = new ChannelFactory<XXXXXXXXXXX >(wsHttpBinding, endpointAddress);
return channelFactory.CreateChannel();
}
--------------------------
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
internal static XXXXXXXXXXX CreateChannelFactory(string url)
{
WSHttpBinding wsHttpBinding = new WSHttpBinding();
wsHttpBinding.Security.Mode = SecurityMode.Transport;
wsHttpBinding.SendTimeout = new TimeSpan(0, 0, 1);
EndpointAddress endpointAddress = new EndpointAddress(url);
var channelFactory = new ChannelFactory<XXXXXXXXXXX >(wsHttpBinding, endpointAddress);
return channelFactory.CreateChannel();
}
留言
張貼留言