Problem with WebService

RaphaelSchindlerRaphaelSchindler USMember ✭✭✭
edited June 2018 in Visual Studio

Hi.
I'm trying to get a project to work where I consume a WebService. It's an SOAP Service. I want to have the WebService-Code shared for android and iOS so I'm trying to put that in with a class library and shared code. But I don't get it to work. I get this exception: Operation 'SaveKontaktAsync' contains a message with parameters. Strongly-typed or untyped message can be paired only with strongly-typed, untyped or void message

This is my code app code in android:

    private mCRMService webService = new mCRMService();
    private EditText username, password;
    private ProgressDialog dialog;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);
        try
        {
            webService.Init();
        }
        catch (Exception ex)
        {
            string error = ex.Message + ":" + ex.StackTrace;
        }
        username = FindViewById<EditText>(Resource.Id.username);
        password = FindViewById<EditText>(Resource.Id.password);

        Button loginBtn = FindViewById<Button>(Resource.Id.loginBtn);

        loginBtn.Click += (object sender, EventArgs e) =>
        {
            loginBtnClicked(sender, e);
        };
    }

I get the exception on the line webService.Init()

That's the code for Init():

public void Init()
    {
        var address = new EndpointAddress(@"http://mcrmservice.monad.de/Webservice.asmx?wsdl");
        //const string endPointName = "WebServiceSoap";

        var binding = new BasicHttpBinding
        {
            Name = "unsecureBinding",
            HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
            ReceiveTimeout = new TimeSpan(0, 10, 0),
            OpenTimeout = new TimeSpan(0, 10, 0),
            CloseTimeout = new TimeSpan(0, 10, 0),
            MaxBufferSize = 65536,
            MaxBufferPoolSize = 524288,
            TransferMode = TransferMode.Buffered,
            Security = { Mode = BasicHttpSecurityMode.None }
        };

        ChannelFactory<mCRMWebService.WebServiceSoap> factory = new ChannelFactory<mCRMWebService.WebServiceSoap>(binding);

        webService = factory.CreateChannel(address);
    }

I hope you can help me. If you need more information just ask.

Answers

  • GaryGary USMember

    @RaphaelShindler Did you ever get an answer to this? Clearly not from Xamarin as I see......but what was the cause of this if you can remember? I'm experiencing the same thing now.

  • RaphaelSchindlerRaphaelSchindler USMember ✭✭✭

    @Gary I got an answer but with the support via mail. What went wrong here was that I made this over complex. It is pretty simple if you know how to do it :)

    So this is my Init() code now:

    public void Init()
    {
        _httpClient = new HttpClient();
        _httpClient.DefaultRequestHeaders.Accept.Add(new    System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/xml"));
    }
    

    And when I call my API I have made an easy structure that is always the same

    public async Task<string> Login(string username, string password, bool useTestSystem)
    {
        try
        {
            _httpClient.DefaultRequestHeaders.Add("SOAPAction", "http://mcrmservice.monad.de/Webservice/Login");
    
            var soapString = _constructSoapStringHelper.ConstructLoginSoapString(username, password, useTestSystem);
    
            var response =
                await
                    _httpClient.PostAsync(
                    "http://mcrmservice.monad.de/Webservice.asmx?op=Login",
                    new StringContent(soapString, Encoding.UTF8, "text/xml"));
    
            var content = response.Content.ReadAsStringAsync().Result;
            _httpClient.DefaultRequestHeaders.Remove("SOAPAction"); //Important!
            return _parseResponseHelper.ParseLoginResponse(content);
        }
        catch (Exception ex)
        {
            _httpClient.DefaultRequestHeaders.Remove("SOAPAction");
            return ex.Message + ":" + ex.StackTrace;
        }
    }
    

    And sorry for the late response I was on vacation :smile:

Sign In or Register to comment.