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 ...
随机推荐
- jQuery之ajax实现篇
jQuery的ajax方法非常好用,这么好的东西,你想拥有一个属于自己的ajax么?接下来,我们来自己做一个简单的ajax吧. 实现功能 由于jq中的ajax方法是用了内置的deferred模块,是P ...
- 移动端1px边框
问题:移动端1px边框,看起来总是2倍的边框大小,为了解决这个问题试用过很多方法,用图片,用js判断dpr等,都不太满意, 最后找到一个还算好用的方法:伪类 + transform 原理是把原先元素的 ...
- EditText 基本用法
title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...
- C++ 拷贝构造函数和赋值运算符
本文主要介绍了拷贝构造函数和赋值运算符的区别,以及在什么时候调用拷贝构造函数.什么情况下调用赋值运算符.最后,简单的分析了下深拷贝和浅拷贝的问题. 拷贝构造函数和赋值运算符 在默认情况下(用户没有定义 ...
- 那些年【深入.NET平台和C#编程】
一.深入.NET框架 1..NET框架具有两个组件:CLR(公共语言运行时)和FCL(框架类库),CLR是.NET框架的基础 2.框架核心类库: System.Collections.Generic: ...
- 微信小程序二维码推广统计
微信小程序可以通过生成带参数的二维码,那么这个参数是可以通过APP的页面进行监控的 这样就可以统计每个二维码的推广效果. 今天由好推二维码推出的小程序统计工具HotApp小程序统计也推出了带参数二维码 ...
- ORA-00821: Specified value of sga_target 3072M is too small, needs to be at least 12896M
在测试PlateSpine克隆的数据库服务器时,由于资源有限,克隆过来的数据库服务器只给了9G的内存,结果在测试时,老是会出现OOMkiller导致宕机,即out of memory killer,是 ...
- 山寨Unity3D?搜狐畅游的免费开源游戏引擎Genesis-3D
在CSDN上看到了<搜狐畅游发布3D游戏引擎Genesis-3D 基于MIT协议开源>(http://www.csdn.net/article/2013-11-21/2817585-cha ...
- Ubuntu(Linux) + mono + jexus +asp.net MVC3 部署
感谢 张善友 的建议,我把 微信订餐 由nginx 改成 jexus,目前运行状况来说,确实稳定了很多,再次感谢. 部署步骤参考 jexus官网:http://www.jexus.org/ htt ...
- 【AutoMapper官方文档】DTO与Domin Model相互转换(中)
写在前面 AutoMapper目录: [AutoMapper官方文档]DTO与Domin Model相互转换(上) [AutoMapper官方文档]DTO与Domin Model相互转换(中) [Au ...