SOAP web service in Portable Class Library

I have Xamarin Portable Class Library, and I need to connect to SOAP web service. Plan was to communicate with service in portable class, and then access it in iOS, Android, Windows Phone projects. Is this possible? I was able to add web reference in android project, but I can't do that for windows phone. I am using visual studio 2015. Can anyone help?

Answers

  • leninmathileninmathi USMember ✭✭

    windows phone don't support webreference or service reference anymore. i'll support Azure api only. the only way to access your service in windows related project is Azure api, REST api or SOAP api with the help of dependency service.

  • @leninmathi said:
    windows phone don't support webreference or service reference anymore. i'll support Azure api only. the only way to access your service in windows related project is Azure api, REST api or SOAP api with the help of dependency service.

    Thank you for answering. I am beginner, just started learning c# and xamarin. Is there tutorial for what you mentioned? Is it hard to accomplish?

  • leninmathileninmathi USMember ✭✭

    @VukasinPetrovic

    this link might help you in understanding alot.

  • @leninmathi said:
    @VukasinPetrovic

    this link might help you in understanding alot.

    I still can't find solution. Am I missing something or I can't make connection to SOAP based web service in PCL and use that across all platforms (including windows phone)?

  • imkumarsaurabhimkumarsaurabh INMember ✭✭

    What I understand is you need a SoapHelper is your PCL and you want to access it from all platforms. Its possible. You can add soap helper which will have base address and will accept method names and parameters. and then send req acc. below is high level sample:

    `
    private static HttpClient myHttpClient = null;
    private static NetworkCredential myCredentials = null;
    private static CookieContainer myCookies = new CookieContainer();

    if (myHttpClient == null)
    {
    string soapURL = “URL”;
    if (myCredentials == null)
    {

                        myCredentials = new NetworkCredential('test', 'testp[');
    
                }
                clientHandler = new HttpClientHandler();
                clientHandler.CookieContainer = myCookies;
                clientHandler.PreAuthenticate = true;
                clientHandler.Credentials = myCredentials;
    
                myHttpClient = new HttpClient(clientHandler, false);
                myHttpClient.BaseAddress = new Uri(soapURL);
    
            }  
    

    soapBody = soapEnvelope.AppendChild("soap:Body");
    if (aRequest != null)
    {
    aRequest.SetAttribute("xmlns", "http://test.com");
    soapBody.AttachChild(aRequest);
    }

            response = await myHttpClient.PostAsync(myHttpClient.BaseAddress, new StringContent(soapEnvelope.ToString()));`
    
  • @imkumarsaurabh said:
    What I understand is you need a SoapHelper is your PCL and you want to access it from all platforms. Its possible. You can add soap helper which will have base address and will accept method names and parameters. and then send req acc. below is high level sample:

    `
    private static HttpClient myHttpClient = null;
    private static NetworkCredential myCredentials = null;
    private static CookieContainer myCookies = new CookieContainer();

    if (myHttpClient == null)
    {
    string soapURL = “URL”;
    if (myCredentials == null)
    {

    myCredentials = new NetworkCredential('test', 'testp[');

    }
    clientHandler = new HttpClientHandler();
    clientHandler.CookieContainer = myCookies;
    clientHandler.PreAuthenticate = true;
    clientHandler.Credentials = myCredentials;

                myHttpClient = new HttpClient(clientHandler, false);
                myHttpClient.BaseAddress = new Uri(soapURL);
                
            }  
    

    soapBody = soapEnvelope.AppendChild("soap:Body");
    if (aRequest != null)
    {
    aRequest.SetAttribute("xmlns", "http://test.com");
    soapBody.AttachChild(aRequest);
    }

            response = await myHttpClient.PostAsync(myHttpClient.BaseAddress, new StringContent(soapEnvelope.ToString()));`
    

    Thank you for answer. What type of variable are "soapBody", "soapEnvelope", "aRequest"?

  • imkumarsaurabhimkumarsaurabh INMember ✭✭

    All three are XmlElements.

  • @imkumarsaurabh said:
    All three are XmlElements.

    Can you send me full code that you used?

Sign In or Register to comment.