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:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With