Link to home
Create AccountLog in
Avatar of Marthaj
MarthajFlag for United States of America

asked on

testing a web service created by VS 2019

I have been trying for weeks :(  to successfully test a web service that has been created without using VS 2019. I can create the web service but my app to test the web service just won't work and I am really running out of time.

So I decided to try to use VS 2019 to create the web service and test it. 

I have no experience with VS 2019. But did a lot of reading/researchng.

In VS 2019, I selected as a project WCF Service and using the coding below, was able to build the service. Or at least that is what I think I did - it successfully was built.

But now I need to test it and am a stump chump on how to do so. I just don't get how I can do that. 

I need to give the client a https link that they will use to pass an xml document to my web service where the web service will then insert it into a MS Sql table. 

When I manually created the web service to produce a link for them to use, it keep using localhost instead of the domain name. 

Below is the coding:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Xml;
using System.Data.SqlClient;


namespace RevisedXml.Test.ServiceXml
{
    // Define the service contract
    [ServiceContract]
    public interface ReviseTestImport
    {
        // Define the operation contract
        [OperationContract]
        string ProcessXmlDocument(string xmlDocument);
    }

    // Implement the service contract
    public class RevXmlService : ReviseTestImport
    {
        public string ProcessXmlDocument(string xmlDocument)
        {
            try
            {
                // Save String to Insert into Database
                var ReturnValue = string.Empty;
                var savXmlStrSnd = xmlDocument;
 
                using (SqlConnection openCon = new SqlConnection("Server=myServer;Database=myDatabase;User Id=myUser;Password=myPassword;"))
                {
                    string saveInfo = "INSERT into DOCS_XML(RcvdXML) VALUES (@RcvdXML)";


                    using (SqlCommand querySaveInfo = new SqlCommand(saveInfo))
                    {
                        querySaveInfo.Connection = openCon;
                        querySaveInfo.Parameters.AddWithValue("@RcvdXML", savXmlStrSnd);
                        
                        openCon.Open();


                        querySaveInfo.ExecuteNonQuery();
                    }
                }
                 return ReturnValue;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
    }
}

Open in new window

 I am a real dummy when it comes to this and need help on how I go about testing it.

Any help appreciated.


ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Marthaj

ASKER

Thank you for responding. 

Stupid me! I forgot that I would need to "publish" the project to the IIS web Server - that's

That was easy to do. Now, I guess I need to figure out how to test it.

Once it has been published, does that mean the web service has been created ??


Thank you. 

You posted a snipet that deals with interacting with sql server.

If my reading is correct, the snippet is a mechanism to get XML data and jnsert it.

What are the other pages that provide user interaction do?