我IDispatchMessageFormatter實施dispatchOperation.Formatter NULL時調用SOAP服務
class ServerMessageFormatter : IDispatchMessageFormatter
{
private IDispatchMessageFormatter Formatter;
public ServerMessageFormatter(IDispatchMessageFormatter formatter)
{
this.Formatter = formatter;
}
public void DeserializeRequest(System.ServiceModel.Channels.Message message, object[] parameters)
{
Formatter.DeserializeRequest(message, parameters);
}
}
和OperationBegavior
public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
{
ServerMessageFormatter Formatter = new ServerMessageFormatter(dispatchOperation.Formatter);
dispatchOperation.Formatter = Formatter;
}
,並調用SOAP服務
GetInfoRequest message = CheckedFields;
string soap = @"<?xml version=""1.0"" encoding=""utf-8""?>
<soap12:Envelope xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">
<soap12:Header>
<Action soap12:mustUnderstand=""1"" xmlns=""http://www.w3.org/2005/08/addressing"">ServiceModel/IService/GetSoapData</Action>
</soap12:Header>
<soap12:Body>
<GetInfoRequest xmlns=""ServiceModel"">
<Data xmlns:d4p1=""http://schemas.microsoft.com/2003/10/Serialization/Arrays"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""/>
</GetInfoRequest>
</soap12:Body>
</soap12:Envelope>";
XmlSerializer serializer = new XmlSerializer(typeof(GetInfoRequest));
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://dev.add.renault.com/Service.svc/soap");
MemoryStream stream1 = new MemoryStream();
serializer.Serialize(stream1, message);
stream1.Position = 0;
StreamReader sr = new StreamReader(stream1);
string t = sr.ReadToEnd();
t = t.Remove(0, 22).Trim();
t = string.Format(soap, t);
ASCIIEncoding encoding = new ASCIIEncoding();
request.Timeout = 99999999;
request.ContentLength = t.Length;
request.Method = "POST";
request.ContentType = "application/soap+xml; charset=utf-8";
request.Accept = "application/soap+xml; charset=utf-8";
using (Stream stm = request.GetRequestStream())
{
using (StreamWriter stmw = new StreamWriter(stm))
{
stmw.Write(t);
}
}
var response = (HttpWebResponse)request.GetResponse();
var abc = new StreamReader(response.GetResponseStream());
問題是,當我打電話給我REST服務並在DeserializeRequest中設置斷點我看到Formatter已經設置了val來自Operation Behavior。但是,當調用soap服務我的格式化程序有空值和反序列化被中止。爲什麼在撥打肥皂時我有這個問題?任何想法?
可惜的是,我不能在火行爲Operaration斷點,看看什麼樣的價值有dispatchOperation ...
是的我使用webHttpBinding休息和customBinding肥皂。爲了休息我在WebHttpBehavior中添加格式化程序。有可能我不會將它添加到肥皂綁定中。哪些部分的代碼ID後u鏈接負責將格式化程序添加到肥皂綁定?我有問題找到它:/ – netmajor
你說得對。我必須添加到我的customEndpoint webhttpBehavior中 – netmajor