c# - 用于 Android 或 Java 和 WCF 的单声道

标签 c# java wcf mono xamarin.android

我目前正在使用 Mono for Android 开发移动应用程序。我一直在尝试通过向其添加 Web 引用来使用 WCF Web 服务,但我似乎无法以这种方式进行调用。我现在正在考虑咬紧牙关,使用我不擅长的 Java 重写代码,因为我不擅长 C#。

我有两个问题:

  1. 如何使用 Mono for android 使用 WCF 网络服务。
  2. 如果我要使用 java,我将如何调用如下所示的方法:

    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "/MyMethod",
               RequestFormat = WebMessageFormat.Json,
               ResponseFormat = WebMessageFormat.Json)]
    void MyMethod(CustomObjectFromDataContract c_Object);
    

当我进行调用时,我收到一个 MessageBox,其中显示未处理的异常 System.Net.WebException:。当我进入代码时,我发现错误发生在您调用

  [System.Web.Services.Protocols.SoapDocumentMethodAttribute    ("http://tempuri.org/IMyService/MyMethod", RequestNamespace="http://tempuri.org/",    ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    public void MyMethod([System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]   CustomObjectFromDataContract c_Object) {
    this.Invoke("MyMethod", new object[] {
                    c_Object});
    }

调用是抛出异常的那个。

最佳答案

我已经解决了这个问题。以下是完成这项工作的步骤: 1.服务必须是RESTful服务 2. 而不是引用 Localhost(我在生成的代码中)使用主机的 IP 地址。我认为这是因为 Android 在 Dalvik VM 中运行,我怀疑它与我的开发计算机正在使用的本地主机不同。 我这样做了,我的服务现在可以正常工作了。

关于c# - 用于 Android 或 Java 和 WCF 的单声道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9167397/

相关文章:

C# 将字符串日期格式转换为另一个字符串的最佳方法?

java - 如何使用 args4j 验证选项?

java - 错误号 : 150 "Foreign key constraint is incorrectly formed-mysql

jquery - 将 JQGrid 与 WCF Web 服务结合使用

c# - 服务总线 WCF 中继 "An error occurred while transmitting data."

c# - UWP Apps 中的模拟框架

c# - 我可以在自定义 ConfigurationSection 上使用 IntegerValidator 属性指定范围吗?

c# - 一般将对象转换为 'real' 类型

java - 单元测试 Blobstore API

jquery - 错误: Cannot process the message because the content type 'application/json; charset=utf-8 was not the expected type