0

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:

  1. 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?
  2. 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
  3. There is a ConnectedService.json auto generated which also holds a static URI including Domain :
{
  "ExtendedData": {
    "inputs": [
      "https://DOMAIN/wsdl/mailing"
    ], [.......]
  1. 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)

JoMaFrCr
  • 1
  • 1
  • A HTTP connection has a server (listener) and a client. You cannot change the endpoint of the server once the listener is started. The client can send to multiple routes which is the URI. The method GetEndpointAddress is getting the route from the active services. – jdweng Jun 20 '23 at 14:07
  • Thanks - my "BaseService" is used by a service which is dependency indejted by transient, so it is created new each time; each single request of course only has one endpoint - so that should not be the problem – JoMaFrCr Jun 20 '23 at 14:35
  • See following : https://learn.microsoft.com/en-us/dotnet/framework/wcf/samples/multiple-endpoints – jdweng Jun 20 '23 at 14:52
  • The solution to [this case](https://stackoverflow.com/questions/13742065/wcf-service-exposing-2-endpoints-on-2-different-service-contracts) may help you. – Jiayao Jun 21 '23 at 03:33

0 Answers0