I have a library for accessing a third party SaaS solutions API (SOAP). It is connected via WCF, which is working fine so far.
The SaaS Application has different tenants under different domains, and I want my application to be able to access multiple of those.
I haven't found the right one and for some of the places where it is hardcoded, I don't have an idea how to change it:
- In the auto generated Interface "...WebservicePort" I have an attribute:
[System.ServiceModel.ServiceContractAttribute(Namespace="DOMAIN/soap/mailing", ConfigurationName="WebserviceService.WebservicePort")]
. Maybe this is it, but I cannot use dynamic values in attributes, can I? - In the method definition of the interface (see 1.) I have:
[System.ServiceModel.OperationContractAttribute(Action="https://DOMAIN/soap/mailing#create", ReplyAction="*")]
. I assume that is the type definition which should be fine, since all models across all domains are equal - There is a ConnectedService.json auto generated which also holds a static URI including Domain :
{
"ExtendedData": {
"inputs": [
"https://DOMAIN/wsdl/mailing"
], [.......]
- Lastly there is the Method GetEndpointAddress, which should not be accessed as far as I understand, but I include here:
private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.WebservicePort))
{
return new System.ServiceModel.EndpointAddress("https://DOMAIN/soap/mailing");
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}
Any ideas?
Notice: I found this Dynamically change WCF endpoint address using a behavior which discussed a similar problem - but I don't think it was solved.
Thanks!
Best, Jonathan
The Reference.cs (automatically generated) file is untouched. I have a "BaseService.cs" for object initialisation, which is selecting the right endpoint, for each one it is:
endpoint = new EndpointAddress(new Uri(domain + "/soap/mailing"));
factoryMailing = new ChannelFactory<WebserviceMailing2Port>(basicHttpBinding, endpoint );
factoryMailing.Credentials.UserName.UserName = UserName;
factoryMailing.Credentials.UserName.Password = Password;
client = factoryMailing.CreateChannel();
But the application seems to use hardcoded endpoint addresses.
Changes
as mentioned by jdweng I am using my "BaseService" in a service, which is used via dependency injection AddTransient - so it is created new each time. So each individual Request has one singular endpoint, but I want to be able to perform requests to different Domains. (Otherwise I only see the option to duplicate the API-Library for each domain which would be quite a mess)