android调用wcf
1. WCF服务端未开启,客户端调用方法出错,客户端如何判断服务端是否启动
什么服务器端…?你用android系统装在某硬件上充当服务器么?
你问的是adbd server吧?随手机启动。
在pc/mac/linux用对应客户端adb devices即可察看连接上的android设备
如有其他问题,可以继续追问,您的采纳是我前进的动力!
2. Android客户端调用wcf接口,为什么传入Byte类型的参数不行
WCF的接口如下
C# code?
1
string SaveByteToFile(bool isNew,string fullLocalPath, string newfileName, byte[] byteArray);
3. 如何发送多个参数,从 android 到 wcf 服务器使用 ksoap2
若要发送多个参数、 字符串、 整数,等等:
SoapObject request = new SoapObject(NAMESPACE, METHOD);
PropertyInfo variableHeight = new PropertyInfo();
variableHeight.setName("height");
variableHeight.setValue(value); // your variable value
variableHeight.setType(Integer.class); // if its string type change to String.class
request.addProperty(variableHeight);
PropertyInfo variableWidth = new PropertyInfo();
variableWidth.setName("width");
variableWidth.setValue(value);
variableWidth.setType(Integer.class);
request.addProperty(variableWidth);
但用于发送字节数组我不太清楚,看看这个: http://code.google.com/p/ksoap2-android/issues/detail?id=116
4. android开发中,如何连接服务器,从服务器读取到数据
服务器端生成JSON:
使用HttpURLConnection连接,通过JSON格式传递对象数据
java"> URLurl=newURL(urlpath);
HttpURLConnectionconn=(HttpURLConnection)url.openConnection();
InputStreaminStream=conn.getInputStream();
=newByteArrayOutputStream();
byte[]data=newbyte[1024];
intlen=0;
while((len=inStream.read(data))!=-1){
outStream.write(data,0,len);
System.out.println(len);
}
inStream.close();
byte[]rlt=outStream.toByteArray();
returnnewString(rlt);
5. wcf和android怎么进行双工通信
第一:在服务契约上标注一下你的回调契约是哪个即可。
[ServiceContract(CallbackContract = typeof(你的回调契约类型))]
第二:回调契约就是用于服务端控制客户端的。比如,一个典型场景是,客户端提交请求以后立即返回;服务端处理一段时间后,再通知客户端结果。
第三:“假如我有一个总控制台,想控制下面的各个客户端,是不是必须使用wcf双工技术才能实现?”是的。
第四:“QQ的远程操作要用什么技术弄呢”这个就比较复杂了。简而言之,就是操作端往接收端发送指令,接收端根据指令来操作,并返回画面数据。比如,操作端发送鼠标键盘的信息,接收端把这些信息变成Windows消息,发送给操作系统(相当于重现一次鼠标键盘操作)。
6. wcf web服务用什么调用方法
1. 创建服务
2. 修改接口
为了做演示,我们将默认的那个Operation修改一下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
namespace WebApplication1
{
// 注意: 如果更改此处的接口名称 "INorthwindService",也必须更新 Web.config 中对 "INorthwindService" 的引用。
[ServiceContract]
public interface INorthwindService
{
[OperationContract]
[WebGet(UriTemplate="HelloWorld")]
string HelloWorld();
}
}
注意,我们这里加了一个WebGet的Attribute,这将允许WCF服务直接通过地址调用
3. 实现服务
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WebApplication1
{
// 注意: 如果更改此处的类名 "NorthwindService",也必须更新 Web.config 中对 "NorthwindService" 的引用。
public class NorthwindService : INorthwindService
{
#region INorthwindService 成员
public string HelloWorld()
{
return "Hello,world";
}
#endregion
}
}
这里的实现依然是我最喜欢的HelloWorld
4. 修改配置文件(web.config),要支持直接通过WebGet的方法调用WCF服务,必须用一个特殊的binding,是webHttpBinding
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="WebApplication1.NorthwindServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug ="false" />
behavior>
serviceBehaviors>
<endpointBehaviors>
<behavior name="test">
<webHttp/>
behavior>
endpointBehaviors>
behaviors>
<services>
<service behaviorConfiguration="WebApplication1.NorthwindServiceBehavior"
name="WebApplication1.NorthwindService">
<endpoint address="" binding="webHttpBinding" contract="WebApplication1.INorthwindService" behaviorConfiguration="test">
<identity>
<dns value="localhost" />
identity>
endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
service>
services>
system.serviceModel>
上面的粗斜体部分是要添加或者修改的
7. Android与WCF传输数据类型Wcf如果不拼XML,不做序列化!手机怎么与之交互
我的方案是:中间建立一个代理网站, android 访问代理网站,代理网站调用WCF,将WCF返回的数据序列化成json返回给android。
代理网站可以采用1. asp.net WebForm, 2. asp.net webAPI
当采用WebForm,安卓访问url.aspx,参数通过url QueryString传递, 页面WCF返回结果直接写入相应流中。
当采用webAPI,这个相对复杂点,还要处理跨域,验证等问题。而且还要ASP.NET MVC 4才支持。
8. android和winform能调用同一个wcf服务吗
您好,(1)在类文件中,添加using语句来导入下面的名字空间:
·System.ServiceModel
·System.Configuration
·DerivativesCalculatorService
(2)代码看起来应该如下所示:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; using System.ServiceModel; using DerivativesCalculatorService; namespace Host { class Program { static void Main(string[] args) { } } }
(3)在Main方法中添加下面的代码:
static void Main(string[] args) { Type serviceType = typeof(Calculator); using (ServiceHost host = new ServiceHost(serviceType)) { } }
第一行WCF服务宿主程序的代码得到一个类型引用,这个类型就是具体实现WCF服务的那个类,也是我们将要在宿主程序中运行的类。
using语句用来对ServiceHost实例进行初始化,在作用域结束时ServiceHost的Dispose()会被自动调用。
(4)在using语句内部,我们先启动ServiceHost,然后通过等待用户输入的方式来阻止应用程序退出。
(5)下面是完整的WCF服务宿主程序代码,新增的代码加亮显示。
namespace Host { class Program { static void Main(string[] args) { Type serviceType = typeof(Calculator); using (ServiceHost host = new ServiceHost(serviceType)) { host.Open(); Console.WriteLine("The calculator service is available."); Console.ReadKey(); } } } }
(6)选择File | Save All菜单项。
(7)在进入下一个任务之前请确保解决方案能够编译通过(按CTRL+Shift+B快捷键)。
9. 如何调用带参数的WCF方法
[OperationContract(Name="sayHelloJson")]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "sayHello", BodyStyle = WebMessageBodyStyle.Wrapped)]
String sayHello();
[OperationContract(Name = "SendMessageJson")]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "SendMessage/{Message}", BodyStyle = WebMessageBodyStyle.Wrapped)]
String SendMessage(String Message);
比如说第一个不带参数的:http://localhost:8000/Service/Json/sayHello
那么第二个带参数的应该怎么调用?(比如说参数是"abc")
我指的是在浏览器中或java的httpclient中,因为我准备在android上实现客户端,所以.net的调用方式就不必讲了。
你URITemplate已经设置了。Get方式。
我猜测一下调用的URL应该是: 网站URL/SendMessage/你好
另外建议你使用REST WCF自带的一个帮助页面,里面会给出更精确的调用示例。
10. c#visualstudio安卓 引用wcf 怎么没有client
CF奖券C可以在游戏商城的超值礼包中进行抽奖,有一定概率获得官方提供的一定天数的武器及道具。具体购买步骤如下: 打开游戏客户端,登录个人QQ号码。选择大区,进入游戏。 点击上方的" 超值礼包"。如下图: 点击后,选择C礼包,即可购买。官方价格如下图: