Click here to Skip to main content
15,906,766 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a function calling API shown below
Now, How do i get the information I am passing like userId and memberId from wsdlUri

public SyncService1()
            siteInfo.AdminLogin = ConfigurationManager.AppSettings["adminID"].ToString();
            siteInfo.AdminPassword = ConfigurationManager.AppSettings["adminPWD"].ToString();
            siteInfo.wsdlUri = ConfigurationManager.AppSettings["uri"].ToString();
            siteInfo.LoggingDirectory = ConfigurationManager.AppSettings["LoggingDirectory"].ToString();
            log.Info($"Logging directory is located in {siteInfo.LoggingDirectory}");
            Console.WriteLine($"Logging directory is located in {siteInfo.LoggingDirectory}");

            // Initialize log4net.

I am expecting
siteInfo.wsdlUri.Userid=`your text`
siteInfo.wsdlUri.MemeberId=`your text`

What I have tried:

siteInfo.wsdlUri.Userid=`your text`
siteInfo.wsdlUri.MemeberId=`your text`
Updated 30-Jan-24 6:27am

1 solution

You can use the System.Uri class to parse the URI and extract the desired information.
siteInfo.wsdlUri = ConfigurationManager.AppSettings["uri"].ToString();
string uri = siteInfo.wsdlUri;
System.Uri parsedUri;

// To validate the URI format
if (Uri.TryCreate(uri, UriKind.Absolute, out parsedUri))
	// Here you can use it from query parameters
	siteInfo.wsdlUri.UserId = parsedUri.QueryParameters["UserId"];
	siteInfo.wsdlUri.MemberId = parsedUri.QueryParameters["MemberId"];
	Console.WriteLine("Invalid URI format");
If the URI doesn't contain query parameters, and the information is encoded in a different way, you'll need to adjust the parsing logic accordingly.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900