Sending SOAP message with C# Help Needed

后端 未结 4 1189
我寻月下人不归
我寻月下人不归 2020-12-16 07:00

I would like to send a SOAP Message to a Web Service and read the response. My code is as follows: I will appreciate your help.

I hope my question is not repeate

4条回答
  •  孤街浪徒
    2020-12-16 07:36

    The web service you are trying to consume offers a WSDL at the following address. So simply right click on the References in the solution explorer and use the Add Service Reference dialog in Visual Studio and point to the WSDL and it will generate strongly typed classes for you to easily consume the service, just like this:

    protected void sendSoapMessage()
    {
        using (var client = new RegistrationBindingsClient("RegistrationBindings"))
        {
            var registration = new RegistrationType();
            registration.Source = new SourceType();
            registration.Source.SourceID = "50001255";
            registration.Email = "adsvine@gmail.com";
            registration.FirstName = "Muz";
            registration.LastName = "Khan";
            var countryUK = new CountryTypeUK();
            countryUK.CountryID = 2000077;
            countryUK.Language = 2000240;
            countryUK.Address = new AddressTypeUK();
            countryUK.Address.Postalcode = "N19 3NU";
            registration.Item = countryUK;
            registration.DOB = new DateTime(1977, 3, 8);
            registration.Gender = 2000247;
    
            client.SubmitPanelist(registration);
        }
    }
    

    See how easy it is. You should not worry about any SOAP and XML plumbing.

    And if you are interested in the actual underlying SOAP envelope that is being sent on the wire using this request:

    
        
            
                
                    
                        50001255
                    
                    adsvine@gmail.com
                    Muz
                    Khan
                    
                        2000077
                        2000240
                        0
                        0
                        
    N19 3NU
    1977-03-08 2000247

提交回复
热议问题