Мне удалось заставить его работать, просто создав IRequestChannel, и чтение следующего помогло объяснить, как это работает
Код для отправки сообщения:
private static void TestDispatchingMessage()
{
var reader = XmlDictionaryReader.CreateBinaryReader(new FileStream(@"path\request_6c6fc02f-45a7-4049-9bab-d6f2fff5cb2d.xml", FileMode.Open), XmlDictionaryReaderQuotas.Max);
var message = Message.CreateMessage(reader, int.MaxValue, MessageVersion.Soap11);
message.Headers.To = new System.Uri(@"url");
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None)
{
MessageEncoding = WSMessageEncoding.Mtom,
MaxReceivedMessageSize = int.MaxValue,
SendTimeout = new TimeSpan(1, 0, 0),
ReaderQuotas = { MaxStringContentLength = int.MaxValue, MaxArrayLength = int.MaxValue, MaxDepth = int.MaxValue }
};
var cf = new ChannelFactory<IRequestChannel>(binding, new EndpointAddress(@"url"));
foreach (OperationDescription op in cf.Endpoint.Contract.Operations)
{
op.Behaviors.Remove<DataContractSerializerOperationBehavior>();
op.Behaviors.Add(new ProtoBehaviorAttribute());
}
cf.Open();
var channel = cf.CreateChannel();
channel.Open();
var result = channel.Request(message);
Console.WriteLine(result);
channel.Close();
cf.Close();
}
Это то, что было в IDispatchMessageInspector
классе:
public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
{
var callId = Guid.NewGuid();
var action = request.Headers.Action.Substring(request.Headers.Action.LastIndexOf('/'));
var fileName = string.Format(@"path\{0}_{1}.data", action, callId);
try
{
var buffer = request.CreateBufferedCopy(int.MaxValue);
var writeRequest = buffer.CreateMessage();
using (var stream = new FileStream(fileName, FileMode.CreateNew))
{
using (var writer = XmlDictionaryWriter.CreateBinaryWriter(stream))
{
writeRequest.WriteMessage(writer);
writer.Flush();
}
}
request = buffer.CreateMessage();
buffer.Close();
}
catch (Exception ex)
{
Log.ErrorException("Error writing", ex);
}
Log.Info("Call {0}", callId);
return callId;
}