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禮包,即可購買。官方價格如下圖: