Android 访问 wcf
IService1.cs
添加的接口
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
TranslateResult jsonData2(FileData data);
定义的 数据复杂类型
// 使用下面示例中说明的数据约定将复合类型添加到服务操作。
[DataContract]
public class FileData
{
[DataMember(Name = "FileName")]
public string FileName { get; set; }
[DataMember(Name = "Length")]
public long Length { get; set; }
[DataMember(Name = "DeviceName")]
public string DeviceName { get; set; }
[DataMember(Name = "UserType")]
public string UserType { get; set; }
[DataMember(Name = "SourceLanguage")]
public string SourceLanguage { get; set; }
[DataMember(Name = "TargetLanguage")]
public string TargetLanguage { get; set; }
[DataMember(Name = "FileStreamContent")]
public string FileStreamContent { get; set; }
}
[DataContract]
public class TranslateResult
{
[DataMember(Name = "ErrMessage")]
public string ErrMessage { get; set; }
[DataMember(Name = "IsSuccess")]
public bool IsSuccess { get; set; }
[DataMember(Name = "OcrResult")]
public string OcrResult { get; set; }
[DataMember(Name = "TransResult")]
public string TransResult { get; set; }
[DataMember(Name = "procTime")]
public string procTime { get; set; }
}
Service1.svc 中的接口实现
public TranslateResult jsonData2(FileData data)
{
TranslateResult result = new TranslateResult();
if (data == null || data.FileStreamContent == null)
{
result.IsSuccess = false;
result.ErrMessage = "参数无效";
return result;
}
try
{
byte[] bytes = Convert.FromBase64String(data.FileStreamContent);
MemoryStream ms = new MemoryStream(bytes);
string ocrResult = OcrPicOperation(ms);
result.OcrResult = ocrResult;
result.TransResult = TransTargetLanguage(ocrResult, "zh-CHS");
result.IsSuccess = true;
}
catch (Exception ex)
{
result.ErrMessage = ex.Message;
result.IsSuccess = false;
}
return result; }
Web.config
//原来的配置被我注释了,在下面。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfServiceWeb.OCRTranslationService" behaviorConfiguration="android">
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="webHttp" contract="WcfServiceWeb.IOCRTranslationService" />
</service>
</services>
<client>
<endpoint address="http://api.microsofttranslator.com/V2/soap.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_LanguageService"
contract="Translation.LanguageService" name="BasicHttpBinding_LanguageService" />
</client>
<!--添加对上传文件大小的限制-->
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_LanguageService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:05:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="104857600" maxReceivedMessageSize="2147483647"
transferMode="StreamedRequest" useDefaultWebProxy="true">
<readerQuotas maxDepth="3200" maxStringContentLength="104857600"
maxArrayLength="104857600" maxBytesPerRead="104857600" maxNameTableCharCount="104857600" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="wsHttp" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Mtom">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors >
<behavior name="webHttp"> <webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="android">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors> </system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
</configuration> <!--<?xml version="1.0" encoding="utf-8"?>
<configuration> <system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_LanguageService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:05:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="104857600" maxReceivedMessageSize="2147483647"
transferMode="StreamedRequest" useDefaultWebProxy="true">
<readerQuotas maxDepth="3200" maxStringContentLength="104857600"
maxArrayLength="104857600" maxBytesPerRead="104857600" maxNameTableCharCount="104857600" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="wsHttp" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Mtom">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings> <services>
<service name="WcfServiceWeb.OCRTranslationService" behaviorConfiguration="HttpGetBehavior">
<endpoint binding="wsHttpBinding" bindingConfiguration="wsHttp"
contract="WcfServiceWeb.IOCRTranslationService"
address=""/>
</service>
</services> <client>
<endpoint address="http://api.microsofttranslator.com/V2/soap.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_LanguageService"
contract="Translation.LanguageService" name="BasicHttpBinding_LanguageService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="HttpGetBehavior">
--><!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 --><!--
<serviceMetadata httpGetEnabled="true"/>
--><!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 --><!--
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer> </configuration>-->
Android 访问 wcf的更多相关文章
- Android访问WCF服务(使用json实现参数传递)
经过多日努力, 终于勉强弄明白了Android访问WCF服务的方法. 服务端实现 一, 实现服务. 操作契约 [ServiceContract] public interface IService { ...
- Android访问WCF服务
原文链接:http://www.cnblogs.com/VinC/archive/2011/02/24/1964049.html 本章目的: 用Wcf建立可以上Android可以访问的数据服务, 数据 ...
- Android和WCF通信 - 大数据压缩后传输
Android和WCF通信 - 大数据压缩后传输 本帖来源:http://www.cnblogs.com/lykbk/archive/2013/08/15/3259045.html 最近一直在优化项目 ...
- 客户端使用自定义代理类访问WCF服务 z
通常在客户端访问WCF服务时,都需要添加服务引用,然后在客户端app.config或 web.config文件中产生WCF服务的客户端配置信息.若是每添加一个服务都是这样做,这样势必会将比较麻烦,能否 ...
- ajax调用handler,使用HttpWebRequest访问WCF服务
引言 随着手机及移动设备的普及,移动端的应用也进入了热潮.以前PC端的门户网站,大多也均推出了适配移动设备的网站或者APP,再差的也注册了个公众号.在移动应用开发中,目前据我所了解到的解决方案有:1. ...
- 如何解析android访问webservice返回的SoapObject数据(可用)
怎么解析android访问webservice返回的SoapObject数据 本帖最后由 kkDragon123 于 2013-03-26 15:50:07 编辑 我的数据如下:mingdanResp ...
- Android访问远程网页取回json数据
php代码 $array = array( 'username'=>'杨铸', 'password'=>'123456', 'user_id'=>);echo json_enc ...
- 用浏览器访问WCF
在开发的时候,为客户端编写代码访问WCF的方式,我们应该比较熟悉,主要是添加一个代理,然后通过这个代理进行访问. 如果用浏览器访问WCF呢?(其实最终是想在JS里面访问)用浏览器访问.测试Web Se ...
- Wince 中访问WCF服务
由于本文并非WinCE开发普及篇,所以一些WinCE开发和WCF开发的基础还请移步百度和谷歌寻找答案,然后结合本文开发出WinCE中如何访问WCF,谢谢. 开发环境 IDE:Visual Studio ...
随机推荐
- PL/SQL — 函数
函数通常用于返回特定的数据.其实质是一个有名字的PL/SQL块,作为一个schema对象存储于数据库,可以被反复执行.函数通常被作为一个表达式来调用或存储过程的一个参数,具有返回值. 一.建立函数 ...
- Hive(转)
Hive分区表 在Hive Select查询中一般会扫描整个表内容,会消耗很多时间做没必要的工作.有时候只需要扫描表中关心的一部分数据,因此建表时引入了partition概念.分区表指的是在创建表时指 ...
- qt 5 小练习 创建无边框界面
我们大家都知道QT5 自带的界面不是那么美观,并且每个软件我们都发现他们的边框是自定义的,所以我决定写一篇这样的博文,也许已经有许许多多篇大牛写的论文了,但我还是想写一篇记录自己的学习QT的历程 首先 ...
- CoreGraphics之CGContext绘图
0 CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文 1 CGContextMoveToPoint 开始画线 2 CGCon ...
- bp神经网络算法
对于BP神经网络算法,由于之前一直没有应用到项目中,今日偶然之时 进行了学习, 这个算法的基本思路是这样的:不断地迭代优化网络权值,使得输入与输出之间的映射关系与所期望的映射关系一致,利用梯度下降的方 ...
- uva 1476 - Error Curves
对x的坐标三分: #include<cstdio> #include<algorithm> #define maxn 10009 using namespace std; do ...
- Unity3D连接真机调试教程,可抓断点
源地址:http://www.unity蛮牛.com/thread-19586-1-1.html <ignore_js_op> 未标题-1.jpg (52.33 KB, 下载次数: 0) ...
- StatsD!次世代系统监控的核心
在互联网业务蒸蒸日上的今时今日,系统架构日渐复杂,随着软件产品和工程团队的变革,许多开源的监控工具应运而生,其中有一些相当出名,比如 Zabbix.Nagios 还有 StatsD.也有一些问题被大家 ...
- Nagios 邮箱告警的方式太OUT了!
一般来讲,在安装完 Nagios 后,我们做的第一件最正确的事,就是设置它的邮件通知,对吧.因为如果没有这一步骤的话,你怎么能够知道什么时候会出现问题呢? 伴随着成功的初始安装,你即将是你司唯一一个能 ...
- php smarty 缓存和配置文件的基本使用方法
smarty高级部分包括缓存机制和配置文件的调用 下面是代码实现: 文件一,配置文件: #全局变量 title="网站主页" content="一个网站的主体部分&quo ...