How to consume an existing SOAP (asmx) web service in Xamarin.Forms PCL project

Anders_AAnders_A ✭✭USMember ✭✭

I have been hitting my head against the wall lately, trying to figure this one out but to no avail. So I am turning to the forum for help...

As mentioned in the headline, I am trying to figure out how to consume and existing SOAP (asmx) web service in a Xamarin.Forms PCL project.

I have found quite a bit documentation on this matter but so far, I have only found out about the following...

  1. There is no possibility of adding a Web Reference within a PCL project
  2. The alternative is to create one's own service
  3. For this purpose, a proxy (class) must be generated in order to consume the SOAP (asmx) service

I read a lot on this matter but am somehow still not getting the full implementation and what elements are required in detail.

Some links I have so far checked on are these...

https://developer.xamarin.com/guides/xamarin-forms/cloud-services/consuming/asmx/

https://developer.xamarin.com/guides/cross-platform/application_fundamentals/web_services/#asmx

...and this one, although it seems to lack a lot of cohesion and explanation on some missing details...

https://forums.xamarin.com/discussion/64742/soap-web-service-in-portable-class-library

Could someone help me out and either provide some functioning code for this issue or point me into the right direction where I could find more detailed information?

Thanks in advance for any help.

Answers

  • Anders_AAnders_A ✭✭ USMember ✭✭

    Is anybody able to help with the above?

    Any help is really appreciated.

  • JPHochbaumJPHochbaum ✭✭✭ USMember ✭✭✭

    Not sure if this will lead you in the right mode of thinking, but I had issues with Xamarin.Forms only using .net 4.0 API's.

    So I created an interface in my PCL project that had my native projects do the .net 4.5 work for me.

    So if you know how to consume a web service in a non-PCL environment you could do something similar?

    PCL Interface

    namespace AppName
    {
        public interface IGetNativeData
        {
            string SetServerMessage(string message);
            string GetServerMessage();
        }
    }
    

    Native Class using .net 4.5 API, that PCL couldn't use:

    namespace AppName.iOS
    {
        public class GetNativeData : IGetNativeData
        {
            public GetNativeData()
            {
    
    
            }
             string IGetNativeData.GetServerMessage()
            {
                //ToDo implement websocket, if already implemented set up system on what the socket needs to do.
                Socket socket = new Socket();
                //Start Socket and connect, create bool return for this?
                socket.WebSocket();
    
                string message = socket.sendMessageToDevice();
    
    
                // socket.sendMessageToDevice();
                if (message.Length > 1)
                {
                    return message;
                }
                else { return null;}
            }
    
            string IGetNativeData.SetServerMessage(string message)
            {
    
                Socket socket = new Socket();
                socket.ExpandMainList(message);
                return message;
    
            }
    
    
    
        }
    }
    
  • Anders_AAnders_A ✭✭ USMember ✭✭

    @JPHochbaum First of all, thanks for your input. Any help is welcome and can only lead to further inspiration when it comes to finding a solution to the issue described above.

    You mentioned the following...

    So if you know how to consume a web service in a non-PCL environment you could do something similar?

    As a matter of fact, I have previously successfully used an already existing web service (asmx) within a web application. This is now over a year ago but I still have my notes, the code and the links to a video manual I used back then. Thus this was done in a non-PCL environment but I am unsure if it will actually work the same way with Xamarin.Forms which I am using now. I have asked another developer here where I work and he says that due to the nature of the Xamarin.Forms setup it looks like, that the common way of creating a Web Reference by adding it to the project itself isn't available in this case (indicating that it in fact works differently when using Xamarin.Forms). The adding of a Web Reference however is still possible within each of the underlying projects ie. the iOS or Droid, just not in the "main" PCL-Cross Platform project. Instead there is - as mentioned under the three topics in my initial post - talk about creating an alternative proxy class. Problem is just, I have not found enough information (that is..., detailed information) on each of the required steps and don't think, that I can do it off the top of my head just like that.

    However, I will take a deeper look at your code suggestion and also continue to search for more clues on this topic. There has to be some more guidance on this subject somewhere.

    If you should happen to have more input that might help (or anybody else for that matter), please do not hesitate and post it here. I'll study any post with great interest as I have to solve this one way or another.

    Thanks in advance.

  • JPHochbaumJPHochbaum ✭✭✭ USMember ✭✭✭

    I actually have to do the same thing in a project I need to start but haven't started yet. But I will rewrite the code above to give a better idea of how to likely get this done.

    So if I figure it out I will post the pseudo code here.

  • Anders_AAnders_A ✭✭ USMember ✭✭

    @JPHochbaum Sounds great. :) I just stumbled upon another tutorial on the proxy class thingy which I am looking into now. But I'll be on the lookout for your input (and anybody else's) when you are getting into contact with the same issue. It'll be of great help, I'm sure. ;) Thanks again.

  • TiagoRodriguesNesTiagoRodriguesNes ✭✭ USMember ✭✭

    I was able to connect my app to a SOAP webservice.
    As you can see on the link bellow you can't add a service reference in any PCL project.

    https://forums.xamarin.com/discussion/64597/how-to-add-webservice-reference-in-xamarin-forms-portable-project

    So i started a new project removed xamarin.Forms, removed win8, installed Xamarin.Forms and i was able to add the service reference.

    My problem is my app is not sending any request using the webservice methods although i can use them and i dont even have a type of data to construct an isntance of my webservice.

    My question...
    Do i need any additional configuration to actually send the requests and to receive the responses?

  • AwodamAwodam ✭✭ ATMember ✭✭

    @Anders_A if you have any question about adding asmx webservice to pcl project pm me.

  • Anders_AAnders_A ✭✭ USMember ✭✭

    @Awdos Thanks for your reply and the offer. I sent you a PM as you requested yesterday and am looking forward to hearing from you.

    Thanks for helping out.

  • patrickmzpatrickmz ✭✭ USMember ✭✭
    edited January 2018

    Any news how to add asmx in Xamarin.Forms because VS 2015 stopping always :( ?!!

Sign In or Register to comment.