0
我正在使用MonoDroid for C#創建一個概念Android應用程序的概念。 到目前爲止,它看起來不錯。然而,當我使用WCF時,我遇到了麻煩。嘗試在MonoDroid中使用WCF時出錯
這個概念很簡單,用一個名爲「Ping」的方法創建一個返回字符串「Pong」的WCF服務。寫了一個WPF應用程序擊中了服務並且工作正常。但是當嘗試點擊服務時,android應用程序給了我一個奇怪的錯誤。
首先,我得到
System.TypeLoadException: Could not load type '__clientproxy_IService1' from assembly 'dummy, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
at System.MonoType.GetMethodImpl (System.String name, BindingFlags bindingAttr, System.Reflection.Binder binder, CallingConventions callConvention, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) [0x00000] in <filename unknown>:0
at System.Type.GetMethod (System.String name, BindingFlags bindingAttr, System.Reflection.Binder binder, CallingConventions callConvention, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) [0x00000] in <filename unknown>:0
at System.Type.GetMethod (System.String name, System.Type[] types) [0x00000] in <filename unknown>:0
at Mono.CodeGeneration.CodeMethod.UpdateMethodBase (System.Type type) [0x00000] in <filename unknown>:0
at Mono.CodeGeneration.CodeClass.CreateType() [0x00000] in <filename unknown>:0
at System.ServiceModel.ProxyGeneratorBase.CreateProxyTypeOperations (System.Type crtype, Mono.CodeGeneration.CodeClass c, System.ServiceModel.Description.ContractDescription cd) [0x00000] in <filename unknown>:0
at System.ServiceModel.ClientProxyGenerator.CreateProxyType (System.Type requestedType, System.ServiceModel.Description.ContractDescription cd, Boolean duplex) [0x00000] in <filename unknown>:0
at System.ServiceModel.ChannelFactory`1[HelloMonoDroid.IService1].CreateChannel (System.ServiceModel.EndpointAddress address, System.Uri via) [0x00000] in <filename unknown>:0
at System.ServiceModel.ChannelFactory`1[HelloMonoDroid.IService1].CreateChannel (System.ServiceModel.EndpointAddress address) [0x00000] in <filename unknown>:0
at System.ServiceModel.ChannelFactory`1[HelloMonoDroid.IService1].CreateChannel() [0x00000] in <filename unknown>:0
at System.ServiceModel.ClientBase`1[HelloMonoDroid.IService1].CreateChannel() [0x00000] in <filename unknown>:0
at System.ServiceModel.ClientBase`1[HelloMonoDroid.IService1].get_InnerChannel() [0x00000] in <filename unknown>:0
at System.ServiceModel.ClientBase`1[HelloMonoDroid.IService1].get_Channel() [0x00000] in <filename unknown>:0
at HelloMonoDroid.ClientTest.BeginPing (System.AsyncCallback callback, System.Object asyncState) [0x00000] in <filename unknown>:0
at HelloMonoDroid.Activity1.button_Click (System.Object sender, System.EventArgs e) [0x00000] in <filename unknown>:0
此錯誤是在服務器端
[ServiceContract]
public interface IService1
{
[OperationContract]
string Ping();
}
這個接口是服務器端類
public class Service1 : IService1
{
public string Ping()
{
return "Pong";
}
}
服務器端工作正常因爲我的測試WPF應用程序擊中罰款。
Android客戶端端接口使用異步模式,但在使用直接同步調用服務時會導致相同的錯誤。
[ServiceContract]
public interface IService1
{
[OperationContract]
string Ping();
[OperationContract(AsyncPattern = true)]
IAsyncResult BeginPing(AsyncCallback callback, object asyncState);
string EndPing(IAsyncResult result);
}
這是客戶 「代理」 類
class ClientTest : ClientBase<IService1>, IService1
{
public ClientTest(Binding binding, EndpointAddress address)
: base(binding, address)
{
}
public string Ping()
{
return Channel.Ping();
}
public IAsyncResult BeginPing(AsyncCallback callback, object asyncState)
{
return Channel.BeginPing(callback, asyncState);
}
public string EndPing(IAsyncResult result)
{
return Channel.EndPing(result);
}
}
這是做呼叫的代碼。
void CallServer(object sender, EventArgs e)
{
var myBinding = new BasicHttpBinding();
var myEndpointAddress = new EndpointAddress("http://mycomputername:8732/Android/");
_proxy = new ClientTest(myBinding, myEndpointAddress);
_proxy.BeginPing(OnCompletion, null);
}
void OnCompletion(IAsyncResult result)
{
string str = _proxy.EndPing(result);
textbox.Text = "Result is: " + str;
result.AsyncWaitHandle.Close();
}
我希望有人會知道一個解決方案或可以給我一個不同的方法。
您還應該提交一個測試用例的錯誤,以便我們解決該問題。 – 2011-02-25 17:13:55
我剛剛提交了錯誤報告。我的印象是這是我做得不對的事。 – 2011-03-01 05:54:37