我从Web应用程序调用wcf服务方法。它在Windows操作系统的所有浏览器中工作正常并且只调用一次。但是在Mac OS Firefox浏览器中,它会调用两次。
我的SVC.cs文件ServiceBehavior是
[ServiceBehavior(InstanceContextMode =
InstanceContextMode.PerCall,
ConcurrencyMode = ConcurrencyMode.Single,
Namespace ="")]
我的Svc界面
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "StoreXMLInfo",
BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Xml)]
XMLInfoPO StoreXMLInfo(Stream xmlstring);
这是调用服务的代码
string returnstring = null;
WebRequest webRequest = WebRequest.Create(uri); //wcf service uri
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(delegate { return true; });
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes(parameters); //parameters to service method
Stream os = null;
try
{
webRequest.ContentLength = bytes.Length;
os = webRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
}
catch (WebException ex)
{
// catch block
}
finally
{
if (os != null)
{
os.Close();
}
}
try
{
using (var webResponse = webRequest.GetResponse())
{
try
{
var sr = new StreamReader(webResponse.GetResponseStream());
returnstring = sr.ReadToEnd().Trim();
}
catch (Exception exl)
{
// catch block
}
}
}
catch (WebException exc)
{
// catch block
}
任何人都可以帮我修复这个错误吗?
答案 0 :(得分:0)
同样的事情发生在我身上。我在Windows操作系统上使用Firefox。我正在调用ServerCertificateValidationCallback的委托,它正在触发两次。阅读这篇文章后,我在IE中测试了相同的内容,请求只触发一次。不知道为什么它会在Firefox中激发两次。肯定会与Firefox有关。