Becuase monotouch compile to native code, so it has some limitation such as dynamic invoke is not allowed.

But I have a lot class in .net, that I use the ChannelFactory dynamic to invoke the wcf service: new ChannelFactory(myBinding, myEndpoint); Now in monotouch I should use the slsvcutil to generate the wcf proxy class, but the slsvcutil generate a lot of Unnecessary extra code (huge), and Makes consumers difficult to unit test, due to high coupling with the WCF infrastructure through the ClientBase class.

Is there a better solution except the ChannelFactory? I would rather write the code manually, have more control over how services are invoked such as the ChannelFactory.

==========

        ChannelFactory<IMyContract> factory = new ChannelFactory<IMyContract>(binding, endpointAddress);
return factory.CreateChannel();

//==> It throw exception: MonoTouch does not support dynamic proxy code generation. Override this method or its caller to return specific client proxy instance

ChannelFactory<T> has a virtual method CreateChannel(). If this is not overridden, it uses dynamic code generation, which fails on MonoTouch.

The solution is to override it and provide your own compile-time implementation.

Below is an old service implementation of mine that at least used to work on MonoTouch. I split it up into 2 partial classes - the first one being linked in all builds, the 2nd only in the iOS builds (allowing the dynamic generation mechanism to still work on windows).
I've stripped it down to only contain 1 service call.

TransactionService.cs:

public partial class TransactionService : ClientBase<IConsumerService>, IConsumerService
{ public TransactionService()
{
} public TransactionService(string endpointConfigurationName) :
base(endpointConfigurationName)
{
} public TransactionService(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
} public TransactionService(string endpointConfigurationName, EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
} public TransactionService(Binding binding, EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
} public AccountBalanceResponse GetAccountBalance( AccountBalanceQuery query )
{
return Channel.GetAccountBalance( query );
}
}

TransactionService.iOS.cs: ConsumerServiceClientChannel which executes the calls via reflection)

public partial class TransactionService
{
protected override IConsumerService CreateChannel()
{
return new ConsumerServiceClientChannel(this);
} private class ConsumerServiceClientChannel : ChannelBase<IConsumerService>, IConsumerService
{ public ConsumerServiceClientChannel(System.ServiceModel.ClientBase<IConsumerService> client) :
base(client)
{
} // Sync version
public AccountBalanceResponse GetAccountBalance(AccountBalanceQuery query)
{
object[] _args = new object[1];
_args[0] = query;
return (AccountBalanceResponse)base.Invoke("GetAccountBalance", _args);
} // Async version
public IAsyncResult BeginGetAccountBalance(AccountBalanceQuery query, AsyncCallback callback, object asyncState )
{
object[] _args = new object[1];
_args[0] = query;
return (IAsyncResult)base.BeginInvoke("GetAccountBalance", _args, callback, asyncState );
} public AccountBalanceResponse EndGetAccountBalance(IAsyncResult asyncResult)
{
object[] _args = new object[0];
return (AccountBalanceResponse)base.EndInvoke("GetAccountBalance", _args, asyncResult);
} }
}

EDIT: I just tested this with the latest MT (5.2) - it no longer needs all that extra boiler plate I had in there before, just the CreateChannel() override. I've cleaned up the sample code to match.

EDIT2: I added an async method implementation.

from:http://stackoverflow.com/questions/10054581/monotouch-wcf-how-to-consume-the-wcf-service-without-svcutil

Monotouch/WCF: How to consume the wcf service without svcutil的更多相关文章

  1. Difference between WCF and Web API and WCF REST and Web Service

    The .Net framework has a number of technologies that allow you to create HTTP services such as Web S ...

  2. WCF 、Web API 、 WCF REST 和 Web Service 的区别

    WCF .Web API . WCF REST 和 Web Service 的区别 The .Net framework has a number of technologies that allow ...

  3. 转 Difference between WCF and Web API and WCF REST and Web Service

    http://www.dotnet-tricks.com/Tutorial/webapi/JI2X050413-Difference-between-WCF-and-Web-API-and-WCF-R ...

  4. WCF、.Net Remoting、Web Service概念及区别

    此文章主要参考http://www.cnblogs.com/weiweibtm/archive/2013/06/21/3148583.html 参考书籍<WCF全面解析上册>.<WC ...

  5. WCF、Web API、WCF REST、Web Service

    WCF.Web API.WCF REST.Web Service 区别 Web Service It is based on SOAP and return data in XML form. It ...

  6. WCF、Web API、WCF REST、Web Service 区别

    Web Service It is based on SOAP and return data in XML form. It support only HTTP protocol. It is no ...

  7. WCF、Web API、WCF REST、Web Service的区别

    Difference between WCF and Web API and WCF REST and Web Service   The .Net framework has a number of ...

  8. Java与WCF交互(二):WCF客户端调用Java web service【转】

    原文:http://www.cnblogs.com/downmoon/archive/2010/08/25/1807982.html 在上篇< Java与WCF交互(一):Java客户端调用WC ...

  9. http服务 WCF、Web API、Web service、WCF REST之间的区别

      http服务 WCF.Web API.Web service.WCF REST之间的区别 在.net平台下,有大量的技术让你创建一个HTTP服务,像Web Service,WCF,现在又出了Web ...

随机推荐

  1. 左列動態添加菜單Repeater

    前台代碼: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="left.aspx. ...

  2. C语言-删除注释

    C语言中的注释,不嵌套,一律使用/*   */的形式.不过双引号中的/*  */则不能算是注释. 以下是正确的代码 /* * ===================================== ...

  3. spring-boot分环境打包为jar包

    1.pom配置 <!-- 多环境打包 start --> <profiles> <!-- 开发环境配置 --> <profile> <id> ...

  4. CCF CSP 201403-4 无线网络

    CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201403-4 无线网络 问题描述 目前在一个很大的平面房间里有 n 个无线路由器,每个无线路 ...

  5. C语言:1孩半问题

    题目: 一孩半,又称独女户二胎,即中国大陆部分农村的一项计划生育政策,第一胎是女孩的夫妻可以生育第二个子女.如果第二胎有n%人工性别选择干预(选择男孩),试问男女比例为多少.(10分)题目内容: 一孩 ...

  6. 常用网络命令(windows)

      Ping命令的常用参数选项 ·ping IP –t 连续对IP地址执行Ping命令,直到被用户以Ctrl+C中断. ·ping IP -l 3000 指定Ping命令中的数据长度为3000字节,而 ...

  7. HBase错误:ERROR: Can't get master address from ZooKeeper; znode data == null 解决办法

    一.问题背景 使用命令 $ hbase shell 进入hbase的shell之后使用create命令创建表时出现错误:ERROR: Can't get master address from Zoo ...

  8. Ionic Js十八:滑动框

    ion-slide-box 滑动框是一个包含多页容器的组件,每页滑动或拖动切换: 效果图如下:   用法 <ion-slide-box on-slide-changed="slid ...

  9. Bootstrap进阶一:Glyphicons 字体图标

    基本组件是Bootstrap的精华之一,其中都是开发者平时需要用到的交互组件.例如:网站导航.标签页.工具条.面包屑.分页栏.提示标签.产品展示.提示信息块和进度条等.这些组件都配有jQuery插件, ...

  10. ECSHOP的JS文件代入问题

    参考一下默认的js写法就行了<script type='text/javascript' src='themes/ecmoban/js/jquery-1.7.2.min.js'></ ...