我开始在 Android 上使用 mono droid 或 Xamarin,所以,我的想法是重用我已经在 .NET 中使用的大部分代码。
我需要我的 android 和 ios 应用程序做的一件事是调用使用 wcf rest 和 json 编码提供的 Web 服务。
所以我的代码很简单:
WebHttpBinding webBinding = new WebHttpBinding();
EndpointAddress endPointAddress = new EndpointAddress("http://192.168.126.24:8025/Services/SecurityManagement");
ChannelFactory<ISecurityManagement> newFactory = new ChannelFactory<ISecurityManagement>(webBinding, endPointAddress);
newFactory.Endpoint.Behaviors.Add(new WebHttpBehavior() { DefaultOutgoingRequestFormat = System.ServiceModel.Web.WebMessageFormat.Json, DefaultOutgoingResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json });
newFactory.Endpoint.Behaviors.Add(new RestEndPointBehavior());
ISecurityManagement newProxy = newFactory.CreateChannel();
ValidateUserExistenceOutput output = newProxy.ValidateUserExistence(new ValidateUserExistenceInput() { Domain = "CRITICAL", Username = "myUserName" });
足够简单让我开始(至少,这是我对单声道的想法,在.net中重用单声道)
但是当我运行此代码时,我得到以下异常异常:
System.NotSupportedException: Loading...
07-25 10:43:40.922 E/mono ( 1950):
07-25 10:43:40.922 E/mono ( 1950): Unhandled Exception:
07-25 10:43:40.922 E/mono ( 1950): System.NotSupportedException: Conversion from the argument parameterType 'BusinessOrchestration.SecurityManagement.InputObjects.ValidateUserExistenceInput' is not supported
07-25 10:43:40.922 E/mono ( 1950): at System.ServiceModel.Dispatcher.QueryStringConverter.ConvertValueToString (System.Object parameter, System.Type parameterType) [0x00000] in <filename unknown>:0
07-25 10:43:40.922 E/mono-rt ( 1950): at System.ServiceModel.Dispatcher.WebMessageFormatter+WebClientMessageFormatter.SerializeRequest (System.ServiceModel.Channels.MessageVersion messageVersion, System.Object[] parameters) [0x00000] in <filename unkno07-25 10:43:40.922 E/mono ( 1950): at System.ServiceModel.Dispatcher.WebMessageFormatter+WebClientMessageFormatter.SerializeRequest (System.ServiceModel.Channels.MessageVersion messageVersion, System.Object[] parameters) [0x00000] in <filename unknown>:0
07-25 10:43:40.922 E/mono ( 1950): at System.ServiceModel.Description.WebHttpBehavior+ClientPairFormatter.SerializeRequest (System.ServiceModel.Channels.MessageVersion messageVersion, System.Object[] parameters) [0x00000] in <filename unknown>:0
07-25 10:43:40.922 E/mono ( 1950): at System.ServiceModel.MonoInternal.ClientRuntimeChannel.CreateRequest (System.ServiceModel.Dispatcher.ClientOperation op, System.Object[] parameters) [0x00000] in <filename unknown>:0
07-25 10:43:40.922 E/mono ( 1950): at System.ServiceModel.MonoIn
07-25 10:43:40.922 E/mono-rt ( 1950): [ERROR] FATAL UNHANDLED EXCEPTION: System.NotSupportedException: Conversion from the argument parameterType 'BusinessOrchestration.SecurityManagement.InputObjects.ValidateUserExistenceInput' is not supported
07-25 10:43:40.922 E/mono-rt ( 1950): at System.ServiceModel.Dispatcher.QueryStringConverter.ConvertValueToString (System.Object parameter, System.Type parameterType) [0x00000] in <filename unknown>:0
07-25 10:43:40.922 E/mono-rt ( 1950): at System.ServiceModel.Dispatcher.WebMessageFormatter+WebClientMessageFormatter.SerializeRequest (System.ServiceModel.Channels.MessageVersion messageVersion, System.Object[] parameters) [0x00000] in <filename unknown>:0
07-25 10:43:40.922 E/mono-rt ( 1950): at System.ServiceModel.Description.WebHttpBehavior+ClientPairFormatter.SerializeRequest (System.ServiceModel.Channels.MessageVersion messageVersion, System.Object[] parameters) [0x00000] in <filename unknown>:0
07-25 10:43:40.922 E/mono-rt ( 1950): at System.ServiceModel.MonoInternal.ClientRuntimeChannel.CreateRequest (System.ServiceModel.Dispatcher.ClientOperation op, System.Object[] parameters) [0x00000] in <filename unknown>:0
07-25 10:43:40.922 E/mono-rt ( 1950): at System.Servic
The program 'Mono' has exited with code 0 (0x0).
我在 .NET 4.5 应用程序中使用完全相同的代码,它工作正常,似乎在将对象转换为字符串(我想是 json 字符串)时它失败了。
既然它在.NET中工作,它应该直接在单声道中工作吗?
你们有具有复杂输入对象的服务吗?您使用什么 api 进行这些调用?
提前感谢您的所有帮助,
路易斯·皮尼奥