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 ...
随机推荐
- 有关C++ std::string 类的类型转换 其他语言永远无法理解的伤
最近做了个项目,C++的MFC窗口程序,一个基于dialog的学生-图书管理系统,有一些感触,最后会放上一些项目截图和部分代码提供大家参考.如果有什么好方法和建议欢迎指导. 强类型,为什么这么伤 我知 ...
- (转)互联网协议入门 ------ HTTP(1)
作者:阮一峰 原文:http://www.ruanyifeng.com/blog/2012/06/internet_protocol_suite_part_ii.html 我们每天使用互联网,你是否想 ...
- ibatis访问oracle数据库US7ASCII中文乱码问题
今天碰到一个问题,使用ibatis框架访问编码为US7ASCII的oracle数据中文乱码, 找了很久终于有了解决方案 首先 SqlMap-Config.xml按如下配置 <sqlMapConf ...
- Codeforces Round #344 (Div. 2) C. Report
Report 题意:给长度为n的序列,操作次数为m:n and m (1 ≤ n, m ≤ 200 000) ,操作分为t r,当t = 1时表示将[1,r]序列按非递减排序,t = 2时表示将序列[ ...
- 面向站长和网站管理员的Web缓存加速指南
详细了解HTTP缓存控制及为什么要缓存. 英文版: http://www.mnot.net/cache_docs/ 中文版:http://www.chedong.com/tech/cache_docs ...
- uCGUI动态内存管理
动态内存的堆区 /* 堆区共用体定义 */ typedef union { /* 可以以4字节来访问堆区,也可以以1个字节来访问 */ ]; /* required for proper aligne ...
- The partner transaction manager has disabled its support for remote/network transactions.
http://technet.microsoft.com/en-us/library/cc753510(WS.10).aspx
- 【存储器相关】RAM、SRAM、SDRAM、ROM、EPROM、EEPROM、Flash存储器区别
常见存储器概念:RAM.SRAM.SDRAM.ROM.EPROM.EEPROM.Flash存储器可以分为很多种类,其中根据掉电数据是否丢失可以分为RAM(随机存取存储器)和ROM(只读存储器),其中R ...
- 史上最全github使用方法:github入门到精通--备用
[初识Github] 首先让我们大家一起喊一句“Hello Github”.YEAH!就是这样. Git是一个分布式的版本控制系统,最初由Linus Torvalds编写,用作Linux内核代码的管理 ...
- iOS多线程常用类说明--备用参考
iOS的多线程,涉及到如下一些类,这里集中做个介绍,免得混淆. 1.NSTimer 很显然,这是定时器类 2.NSTask iOS 不支持 NSTask 在很多并发操作的时候,多线程太耗资源,也太危险 ...