I want to create a C# application that communicates with two SOAP webservices. These webservices (WSDL files) use the same url
<root>/...dirPath.../dms.cfc?wsdl
<root>/...dirPath.../cobra.cfc?wsdl
<root>
should be dynamic because the application user has to set this variable.
First of all I took this
How can I dynamically switch web service addresses in .NET without a recompile?
and tried this
https://www.codeproject.com/Articles/12317/How-to-make-your-Web-Reference-proxy-URL-dynamic
Further I found this link
but these links didn't help I can't find the settings URL behaviour
and I can't access the URL property by code.
I created a static class that should handle both webservices. The user is able to change the webservice root url.
An example URL would be
http://localhost:8500/CoBRA/...dirPath.../dms.cfc?wsdl
or
http://myInstance.com/CoBRA/...dirPath.../dms.cfc?wsdl
handled by this code
public static class CoBRAService
{
private static cobraClient cobraBaseClient = new cobraClient();
private static dmsClient cobraDmsClient = new dmsClient();
public static void SetWebserviceRootUrl(string rootUrl)
{
// cobraBaseClient.url = $"{rootUrl}/path/dms.cfc?wsdl";
// cobraDmsClient.url = $"{rootUrl}/path/cobra.cfc?wsdl";
}
}
Both webservices don't inherit from System.Web.Services.Protocols.SoapHttpClientProtocol
they implement this public partial class cobraClient : System.ServiceModel.ClientBase<MyProject.CoBRA_Base.cobra>, MyProject.CoBRA_Base.cobra
This is my project structure
Where can I set the webservice url or how can I access the url property?
if your "CoBRA_BaseClient" and "CoBRA_DMSClient" inherited from System.ServiceModel.ClientBase< TChannel > then you can try the following:
public static CoBRA_BaseClient CreateService()
{
CoBRA_BaseClient service = new CoBRA_BaseClient();
service.Endpoint.Address = new EndpointAddress("uri");
return service;
}
public static CoBRA_DMSClient CreateService()
{
CoBRA_DMSClient service = new CoBRA_DMSClient();
service.Endpoint.Address = new EndpointAddress("uri");
return service;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.