Calling a Web Api from a WCF client

leo del ciello 66 Reputation points
2024-09-06T13:01:21.5966667+00:00

Yes , I know its kind of weird .

I have a web app running with 4.5 Framework. It has some Wcf clients configured in web.config to access the usual soap services.

Now I am in a situation where I need to call some Web Api ( whose implementation I don't have access to) and I configured a simple reusable client to be able to use the same syntax for any of them. The client works fine but it reads the configuration of each web api client from an external xml file, which could not be allowed in the production release. 

The configuration requires a minimal complexity , like in the schema below :

 

<microServices>

<microService name="WS1">

<url>...</url>

<jwtToken>…..</jwtToken>

<clientID>80da6...</clientID>

<clientSecret>cf327...</clientSecret>

</microService>

<microService name="Ws2">

<url>...</url>

<jwtToken>…..</jwtToken>

<clientID>......</clientID>

<clientSecret>......</clientSecret>

</microService>

……

…..

</microServices>

 

but i can hardly realize this kind of schema in the web.config of the application, that's why I'm using an external file .  Is there a way to put this kind of configuration in the web.config without making it too complex ?

Moreover, is it possible to configure a <system.serviceModel><client><endpoint ..> .....  entry for a call to a Web Api ? yes I know it's bizarre, to make  a Rest call from a WCF client to a web api, but due to the previous potential problems (inability to use an external file in production and impossibility to insert rest client configuration in web.config) I am just exploring a third option ...

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,479 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 29,331 Reputation points Microsoft Vendor
    2024-09-10T03:22:02.46+00:00

    Hi @leo del ciello,

    is it possible to configure a <system.serviceModel><client><endpoint ..> .....  entry for a call to a Web Api ?

    As far as I know this should be impossible.

    Maybe you could try using <appSettings>.

    <appSettings> element for <configuration>

    How to: Read application settings

    The <appSettings> element stores custom application configuration information, such as database connection strings, file paths, XML Web service URLs, or any other custom configuration information for an application. The key/value pairs specified in the <appSettings> element are accessed in code using the ConfigurationSettings class.

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.