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的更多相关文章

  1. Android访问WCF服务(使用json实现参数传递)

    经过多日努力, 终于勉强弄明白了Android访问WCF服务的方法. 服务端实现 一, 实现服务. 操作契约 [ServiceContract] public interface IService { ...

  2. Android访问WCF服务

    原文链接:http://www.cnblogs.com/VinC/archive/2011/02/24/1964049.html 本章目的: 用Wcf建立可以上Android可以访问的数据服务, 数据 ...

  3. Android和WCF通信 - 大数据压缩后传输

    Android和WCF通信 - 大数据压缩后传输 本帖来源:http://www.cnblogs.com/lykbk/archive/2013/08/15/3259045.html 最近一直在优化项目 ...

  4. 客户端使用自定义代理类访问WCF服务 z

    通常在客户端访问WCF服务时,都需要添加服务引用,然后在客户端app.config或 web.config文件中产生WCF服务的客户端配置信息.若是每添加一个服务都是这样做,这样势必会将比较麻烦,能否 ...

  5. ajax调用handler,使用HttpWebRequest访问WCF服务

    引言 随着手机及移动设备的普及,移动端的应用也进入了热潮.以前PC端的门户网站,大多也均推出了适配移动设备的网站或者APP,再差的也注册了个公众号.在移动应用开发中,目前据我所了解到的解决方案有:1. ...

  6. 如何解析android访问webservice返回的SoapObject数据(可用)

    怎么解析android访问webservice返回的SoapObject数据 本帖最后由 kkDragon123 于 2013-03-26 15:50:07 编辑 我的数据如下:mingdanResp ...

  7. Android访问远程网页取回json数据

    php代码 $array = array(  'username'=>'杨铸',  'password'=>'123456',  'user_id'=>);echo json_enc ...

  8. 用浏览器访问WCF

    在开发的时候,为客户端编写代码访问WCF的方式,我们应该比较熟悉,主要是添加一个代理,然后通过这个代理进行访问. 如果用浏览器访问WCF呢?(其实最终是想在JS里面访问)用浏览器访问.测试Web Se ...

  9. Wince 中访问WCF服务

    由于本文并非WinCE开发普及篇,所以一些WinCE开发和WCF开发的基础还请移步百度和谷歌寻找答案,然后结合本文开发出WinCE中如何访问WCF,谢谢. 开发环境 IDE:Visual Studio ...

随机推荐

  1. iOS极光推送集成步骤

    1.下载SDK,导入Xcode 2.在苹果开发者中心建立AppId与bundleID进行关联,注意勾选推送功能 3.在苹果开发者中心建立推送证书 4.在极光后台建立应用且上传推送证书 5.建立描述文件 ...

  2. 【BZOJ】1012: [JSOI2008]最大数maxnumber 树状数组求区间最值

    题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1012 题意:维护一个数列,开始时没有数值,之后会有两种操作, Q L :查询数列末 ...

  3. Google地图数据算法

    Google Maps与Google Earth中的每个级别的每一副图片都有一个URL,例如下面这幅我们学校的图的地址是http://kh.google.com/kh?v=3&t=trstrq ...

  4. iostream/fstream中的输入输出流指针的绑定,tie函数的使用。

      为了兼容c语言的输入输出,c++里面采用tie将输入输出流经行绑定,所以cin/cout并不是独立的.当执行cin时,cout同时会被执行.反之亦然. by defalut,cin is tied ...

  5. cocos2dx 3.4 截图代码

    Size size = Director::sharedDirector()->getWinSize(); //定义一个屏幕大小的渲染纹理 RenderTexture* pScreen = Re ...

  6. cocos2dx3.4 解析json文件

    头文件: #include "json/document.h" #include "json/stringbuffer.h" #include "js ...

  7. BZOJ 3983 Takeover Wars 解题报告

    我猜了一个结论,能合并就合并,到了必须要敌对交易的时候才进行敌对交易. 然后合并的话,肯定是拿最大的两个去合并. 至于敌对交易,肯定是干掉对方最大的公司才是有意义的. 于是各种分类讨论...看代码好了 ...

  8. ZOJ 2750 Idiomatic Phrases Game(Dijkstra)

    点我看题目 题意 : 给定一本字典,字典里有很多成语,要求从字典里的第一个成语开始,运用字典里的成语变到最后一个成语,变得过程就是成语接龙,后一个成语的第一个字必须有前一个成语的最后一个字相等,给定的 ...

  9. Android TabActivity与Activity之间的动画跳转(主要Tabhost中跳转出来的动画效果解决)

    首先,要说的是ActivityA到ActivityB的切换这个相对简单,只要overridePendingTransition(In,out). 这里不就说了.但是这里要说名的ActivityA不能T ...

  10. org.springframework.jdbc.datasource

    org.springframework.jdbc.datasource.DataSourceUtils /** * Actually obtain a JDBC Connection from the ...