1

I have a problem when calling a web-service(asmx) in Xamarin.forms. My web-service works in Android and I generated it with svcutil.exe, but when I tested it in IOS I got a problem saying:

"Mono touch does not support dynamic proxy code generation"

After searching I found out that I have to use a Silverlight tool called SLSvcutil.exe in order to override the CreateChannel method, and to make it work in IOS. It worked, but I need the methods to be synchronous (not async).

I kept searching how to make a pure synchronous method for my web-service and I found this: Monotouch/WCF: How to consume the wcf service without svcutil

Here is my code:

protected override POService2Soap CreateChannel()
{
    return new POService2SoapClientChannel(this);
}

private class POService2SoapClientChannel : ChannelBase<POService2Soap>, POService2Soap
{

    public POService2SoapClientChannel(System.ServiceModel.ClientBase<POService2Soap> client) : 
            base(client)
    {

    }


 public ClientLoginResponse ClientLogin(ClientLoginRequest request)
        {
            object[] _args = new object[1];
        _args[0] = request)
        return (ClientLoginResponse)base.Invoke("ClientLogin", _args);
        }

I get the interface from the Silverlight-generated code, and I create the LoginResponse class there etc, but the problem comes where i call base.invoke("Client Login",_args).

Basically, the ChannelBase doesn't have an Invoke method, it only has BeginInvoke and EndInvoke. So I get the problem cause there is no Invoke in the ChannelBase class inside ClientBase. How can I invoke this, or does anyone have any better solution for getting synchronous results from the web-service?

P.S. I know why Silverlight has async methods, also I know that it is better to async now, and I also know that web-services (asmx) especially in mobile development are a bit "outdated". But in my case I need it like that.

Thanks in advance.

Frode
  • 3,325
  • 1
  • 22
  • 32
Donjet
  • 63
  • 10
  • If it is an asmx-webservice you should be able to use the wsdl to generate you proxy-classes from Visual Studio. – tequila slammer Aug 20 '18 at 09:02
  • @tequilaslammer well adding a web reference is supported in Xamarin but unfortunately for now it has a bug, and it also generates only the async methods. – Donjet Aug 20 '18 at 09:57
  • I am not aware of a bug while using it last week. Can you go into details? – tequila slammer Aug 20 '18 at 11:12
  • @tequilaslammer well when you try to add a web reference in the portable project, you get an error about this : https://github.com/dotnet/wcf/issues/2464 And also it creates only async methods. But i couldn't get it to work even when i unchecked reuse types in all referenced assemblies. – Donjet Aug 20 '18 at 11:29
  • I think this is related to a .netstandard project. But you are right. It will only generate synchron and event-based-asynchron methods. No task-based ones you can use with async-await-pattern without a little bit of extra work. – tequila slammer Aug 29 '18 at 19:42

0 Answers0