Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mono for Android or Java and WCF

I am currently using Mono for Android to develop a mobile application. I have been trying to consume a WCF web service by adding a web reference to it but I can't seem to make the call that way. I am now considering to bite the bullet and rewrite the code using Java which I am not as good at as I am with C#.

I have 2 questions:

  1. How do I consume a WCF webservice using Mono for android.
  2. If I am to use java how would I call a method that looks like the one below:

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

When I make the call I get a MessageBox that says Unhandled exception System.Net.WebException:. When I step into the code I see that the error happens when you call

  [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});
    }

The invoke is the one throwing the exception.

like image 474
nnyamhon Avatar asked Mar 15 '26 13:03

nnyamhon


1 Answers

I have resolved the issue. Here are the steps to make this work: 1. The service has to be a RESTful service 2. Instead of referencing Localhost (which I was in the generated code) use the IP address of the hosting machine. I think this is because Android runs in Dalvik VM which I suspect has a different local host from the one my Dev computer is using. I did that and my service works now.

like image 100
nnyamhon Avatar answered Mar 18 '26 03:03

nnyamhon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!