最近一段时间,一直在折腾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?的更多相关文章

  1. CentOS7 mono环境连接WCF

    总结下在mono环境中使用Wcf出现的问题以帮助你快速解决问题. 1.昨天在内网Centos7下部署由Windows上开发完成的ASP.NET Mvc4项目,部署到mono环境下遇到了无法找到endp ...

  2. ios下fixed回复框bug的解决方案

    前几天做一个移动端的页面,要加个像微信那样附着在底部的回复框,按照做PC端网页的思路,首先是用fixed,在安卓上测了一下是好的,结果到朋友的iphone6p上就不行了,点击输入框之后它总会跳到屏幕中 ...

  3. jquery的slideUp、slideDown、slideToggle等涉及滑动效果的一系列函数,在IE浏览器下有几处bug

    jquery的slideUp.slideDown.slideToggle等涉及滑动效果的一系列函数,在IE浏览器下有几处bug: 1. 因position引起的问题 影响:IE全系列 症状:在需要sl ...

  4. .Net Core下使用WCF

    在.net core 下的wcf 和framework下的wcf使用方式有点不太一样.在core下用wc,需要安装VS扩展Visual Studio WCF Connected Service,目前这 ...

  5. android一个下拉放大库bug的解决过程及思考

    android一个下拉放大库bug的解决过程及思考 起因 项目中要做一个下拉缩放图片的效果,搜索了下github上面,找到了两个方案. https://github.com/Frank-Zhu/Pul ...

  6. 在IIS8.5的环境下配置WCF的Restful Service

    今天在客户的环境中(Windows Server 2012 R2 + IIS 8.5)搭建Call WCF Restful Service的功能,发现了几个环境配置的问题,记录如下: 1):此环境先安 ...

  7. web标准:img图片在ie6下显示空白的bug解决方案

    在进行页面的DIV+CSS排版时,遇到IE6(当然有时Firefox下也会偶遇)浏览器中的图片元素img下出现多余空白的问题绝对是常见的对于该问题的解决方法也是“见机行事”. 1.将图片转换为块级对象 ...

  8. jquery下ie的margin-left ----bug 以及parseInt方法bug

    ie下使用jquery的方法css('margin-left')可能会出现'auto'----从而使结果不可计算,即便使用parseInt()方法也不行 因为parseInt()方法的bug是如果参数 ...

  9. chrome下float元素下input选中内容bug

    今天在写一个小demo的时候,发现chrome下一个很奇怪的bug. 我的代码如下: <!DOCTYPE html> <html lang="en"> &l ...

随机推荐

  1. js-静态、原型、实例属性

    本篇来说一下js中的属性: 1.静态属性 2.原型属性 3.实例属性 静态属性: function klass(){} var obj=new klass(); klass.count=0; klas ...

  2. MyBatis基础入门--知识点总结

    对原生态jdbc程序的问题总结 下面是一个传统的jdbc连接oracle数据库的标准代码: public static void main(String[] args) throws Exceptio ...

  3. JVM类加载

    JVM的类加载机制就是:JVM把描述类的class文件加载到内存,并对数据进行校验.转换解析和初始化,最终形成可以被JVM直接使用的Java类型 ClassLoader JVM中的ClassLoade ...

  4. 设计模式之单例模式(Singleton)

    设计模式之单例模式(Singleton) 设计模式是前辈的一些经验总结之后的精髓,学习设计模式可以针对不同的问题给出更加优雅的解答 单例模式可分为俩种:懒汉模式和饿汉模式.俩种模式分别有不同的优势和缺 ...

  5. 深入理解css3中nth-child和 nth-of-type的区别

    在css3中有两个新的选择器可以选择父元素下对应的子元素,一个是:nth-child 另一个是:nth-of-type. 但是它们到底有什么区别呢? 其实区别很简单::nth-of-type为什么要叫 ...

  6. 【干货分享】流程DEMO-离职流程

    流程名: 离职申请   流程相关文件: 流程包.xml WebService业务服务.xml WebService.asmx WebService.cs   流程说明: 流程中集成了webservic ...

  7. T-SQL 拆分使用指定分隔符的字符串(split string)

    比如有一个表,我们需要些一个语句像SELECT OtherID, SplitData WHERE SomeID = 'abcdef-.......' , 然后就能返回分割成单独的行. 原表: | So ...

  8. MySQL:常见使用问题

    内容 1.Linux 上安装 MySQL 2.单机上安装多实例 3.不知root密码情况下,修改root密码 1.Linux 上安装MySQL 安装步骤: 1)解压 tar.gz文件 -linux-g ...

  9. VS2010 release编译下进行调试,“当前不会命中任何断点,还没有为文档加载”问题解决方案

    在release模式下调试程序,经常出现"当前不会命中任何断点,还没有为文档加载"的问题,可尝试以下方法: 1. 属性 → 配置属性 → C/C++ → 常规 → 调试信息格式:选 ...

  10. Linux学习日记-(一)

    一.为什么学习Linux 大学时开始接触Linux,最开始学习的是RedHat(小红帽),感觉Linux好像很久不见的老朋友,用起来很舒服(虽然我们用的是DotNet).很喜欢它的命令模式,让我能接触 ...