Mono下的WCF的Bug?
最近一段时间,一直在折腾Mono,折腾Linux。让我无比痛苦的是Mono下的WCF的坑真的是太多了,这不又遇到了一个莫名其妙的问题。
环境:mono 3.2.1,Jexus 5.4.3,OS CentOS 6.2。
1:定义服务契约
using System.ServiceModel; namespace BugTest.Contract
{
[ServiceContract(Name = "Calculator", Namespace = "http://www.wcfbugtest.com")]
public interface ICalculator
{
[OperationContract]
int Add(int x, int y);
}
}
2:实现服务
WriteInfo方法主要是为了记录当时调用Add方法,传入的X,Y值,也是为了更好的展现这个Bug。
using System;
using System.IO;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Text;
using BugTest.Contract; namespace BugTest.Service
{
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class CalculatorService : ICalculator
{
public int Add(int x, int y)
{
WriteInfo(string.Format("x={0},y={1}", x, y));
return x + y;
} public void WriteInfo(string logInfo)
{
var type = Type.GetType("Mono.Runtime");
if (type != null)
{
string filePath = "/var/www/getextent/Logs/Info.log";
using (var sw = new StreamWriter(filePath, true, Encoding.UTF8))
{
sw.Write(logInfo + "\r\n");
sw.Flush();
}
}
}
}
}
3:寄宿服务
主要是看Web.config,我的生产环境客户端使用的是Silverlight,终结点使用的绑定是customBinding,编码方法采用的是Binary Message Encoding,主要是为了减少服务端与客户端传输消息的大小,能够稍微的提升性能。此外,要在Mono下跑WCF,要为站点添加一个Global.asax,在Application_Start添加如下代码:
protected void Application_Start(object sender, EventArgs e)
{
Environment.SetEnvironmentVariable("MONO_STRICT_MS_COMPLIANT", "yes");
}
详细的配置如下:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<customErrors mode="Off"/>
<httpRuntime/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="customBinding0" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00">
<binaryMessageEncoding/>
<httpTransport maxReceivedMessageSize="" maxBufferSize=""/>
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<services>
<service behaviorConfiguration="ServiceBehavior" name="BugTest.Service.CalculatorService">
<endpoint address="http://192.168.8.141:6060/CalculatorService.svc" binding="customBinding" bindingConfiguration="customBinding0" contract="BugTest.Contract.ICalculator"/>
</service>
</services>
</system.serviceModel>
</configuration>
最后发布站点,部署到Linux下面的Jexus Web服务器上。
4:客户端调用
客户端,可以使用控制台应用程序,添加服务引用,输入服务的地址,生成好客户端的代理文件,及App.config文件。
测试代码如下:
using System;
using MonoClient.ServiceReference; namespace MonoClient
{
class Program
{
static void Main(string[] args)
{
var client = new CalculatorClient();
Console.WriteLine("x + y = {2} where x = {0} and y = {1}", -, , client.Add(-, ));
client.Close(); Console.Read();
}
}
}
执行的结果如下:

Log的内容如下:

问题出现了,客户端传入的-1,在服务端莫名其妙地变成了255了。A bug ???
在windows下,使用IIS寄宿服务,是不会有问题。
此外如果使用baseHttpBinding,在Mono下WCF也是不会有问题的。即将配置按下面的方式修改:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="BugTest.Service.CalculatorService" behaviorConfiguration="ServiceBehavior">
<endpoint binding="basicHttpBinding" contract="BugTest.Contract.ICalculator"/>
</service>
</services>
</system.serviceModel>
问题出在哪里呢? 是binaryMessageEncoding的问题吗?
Mono下的WCF的Bug?的更多相关文章
- CentOS7 mono环境连接WCF
总结下在mono环境中使用Wcf出现的问题以帮助你快速解决问题. 1.昨天在内网Centos7下部署由Windows上开发完成的ASP.NET Mvc4项目,部署到mono环境下遇到了无法找到endp ...
- ios下fixed回复框bug的解决方案
前几天做一个移动端的页面,要加个像微信那样附着在底部的回复框,按照做PC端网页的思路,首先是用fixed,在安卓上测了一下是好的,结果到朋友的iphone6p上就不行了,点击输入框之后它总会跳到屏幕中 ...
- jquery的slideUp、slideDown、slideToggle等涉及滑动效果的一系列函数,在IE浏览器下有几处bug
jquery的slideUp.slideDown.slideToggle等涉及滑动效果的一系列函数,在IE浏览器下有几处bug: 1. 因position引起的问题 影响:IE全系列 症状:在需要sl ...
- .Net Core下使用WCF
在.net core 下的wcf 和framework下的wcf使用方式有点不太一样.在core下用wc,需要安装VS扩展Visual Studio WCF Connected Service,目前这 ...
- android一个下拉放大库bug的解决过程及思考
android一个下拉放大库bug的解决过程及思考 起因 项目中要做一个下拉缩放图片的效果,搜索了下github上面,找到了两个方案. https://github.com/Frank-Zhu/Pul ...
- 在IIS8.5的环境下配置WCF的Restful Service
今天在客户的环境中(Windows Server 2012 R2 + IIS 8.5)搭建Call WCF Restful Service的功能,发现了几个环境配置的问题,记录如下: 1):此环境先安 ...
- web标准:img图片在ie6下显示空白的bug解决方案
在进行页面的DIV+CSS排版时,遇到IE6(当然有时Firefox下也会偶遇)浏览器中的图片元素img下出现多余空白的问题绝对是常见的对于该问题的解决方法也是“见机行事”. 1.将图片转换为块级对象 ...
- jquery下ie的margin-left ----bug 以及parseInt方法bug
ie下使用jquery的方法css('margin-left')可能会出现'auto'----从而使结果不可计算,即便使用parseInt()方法也不行 因为parseInt()方法的bug是如果参数 ...
- chrome下float元素下input选中内容bug
今天在写一个小demo的时候,发现chrome下一个很奇怪的bug. 我的代码如下: <!DOCTYPE html> <html lang="en"> &l ...
随机推荐
- ASP.NET Aries 入门开发教程3:开发一个列表页面及操控查询区
前言: Aries框架毕竟是开发框架,所以重点还是要写代码的,这样开发人员才不会失业,哈. 步骤1:新建html 建一个Html,主要有三步: 1:引入Aries.Loader.js 2:弄一个tab ...
- SASS教程sass超详细教程
SASS安装及使用(sass教程.详细教程) 采用SASS开发CSS,可以提高开发效率. SASS建立在Ruby的基础之上,所以得先安装Ruby. Ruby的安装: 安装 rubyinstaller- ...
- 三分钟学会用 js + css3 打造酷炫3D相册
之前发过该文,后来不知怎么回事不见了,现在重新发一下. 中秋主题的3D旋转相册 如图,这是通过Javascript和css3来实现的.整个案例只有不到80行代码,我希望通过这个案例,让正处于迷茫期的j ...
- PowerShell实现批量重命名文件
[string]$FileName="E:\test11" #-------------------------------------- Clear-Host foreach($ ...
- 步入angularjs directive(指令)--点击按钮加入loading状态
今天我终于鼓起勇气写自己的博客了,激动与害怕并存,希望大家能多多批评指导,如果能够帮助大家,也希望大家点个赞!! 用angularjs 工作也有段时间了,总体感觉最有挑战性的还是指令,因为没有指令的a ...
- PhpStorm和WAMP配置调试参数,问题描述Error. Interpreter is not specified or invalid. Press “Fix” to edit your project configuration.
PhpStorm和WAMP配置调试参数 问题描述: Error. Interpreter is not specified or invalid. Press “Fix” to edit your p ...
- python10作业思路及源码:类Fabric主机管理程序开发(仅供参考)
类Fabric主机管理程序开发 一,作业要求 1, 运行程序列出主机组或者主机列表(已完成) 2,选择指定主机或主机组(已完成) 3,选择主机或主机组传送文件(上传/下载)(已完成) 4,充分使用多线 ...
- 嵌入式&iOS:回调函数(C)与block(OC)传 参/函数 对比
C的回调函数: callBack.h 1).声明一个doSomeThingCount函数,参数为一个(无返回值,1个int参数的)函数. void DSTCount(void(*CallBack)(i ...
- How to accept Track changes in Microsoft Word 2010?
"Track changes" is wonderful and remarkable tool of Microsoft Word 2010. The feature allow ...
- Centos、Ubuntu 安装 Mono、Jexus
Mono是.NET的跨平台实现 在众多关于语言的争论中,.NET一直被以不能跨平台而诟病,Mono改变了这一现状. 有人当心Mono会涉及版权啥的问题.高深的偶不懂,不过我觉得Unity3D都能用,为 ...