# Elastic APM not working with .net WCF service

**URL:** <https://discuss.elastic.co/t/elastic-apm-not-working-with-net-wcf-service/290574>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [November 30, 2021, 4:10pm UTC](https://discuss.elastic.co/t/elastic-apm-not-working-with-net-wcf-service/290574 "2021-11-30T16:10:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sharma3007](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sharma3007/32/43414_2.png) [@Sharma3007](https://discuss.elastic.co/u/Sharma3007)\
**Post date:** [November 30, 2021, 4:10pm UTC](https://discuss.elastic.co/t/elastic-apm-not-working-with-net-wcf-service/290574/1 "2021-11-30T16:10:02Z")

</div>

Hi Team,

Elastic APM not working with .net WCF service.  
Please help me how to configure elastic .net apm agent with wcf service.

Its working fine with mvc web application, but not with wcf service.

My application fetching data from sql database by using wcf service.  
So i just want to know the db call trace that how much time it took to execute the store proc command.  
Could you please help me the steps and configurations.  
I am new in APM part.

Thanks in advance!!

---

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [November 30, 2021, 4:29pm UTC](https://discuss.elastic.co/t/elastic-apm-not-working-with-net-wcf-service/290574/2 "2021-11-30T16:29:40Z")

</div>

Hi @Sharma3007,

for WCF you can try setting up the IIS module as described [here in the docs](https://www.elastic.co/guide/en/apm/agent/dotnet/current/setup-asp-dot-net.html). This may not capture all bindings - if it's a HTTP based WCF setup, then likely it'll capture your transactions, if it's more low level maybe it won't.

If the automatic capturing of the transaction doesn't work, you could try manual instrumentation by starting the transaction manually as described [here](https://www.elastic.co/guide/en/apm/agent/dotnet/current/public-api.html#api-start-transaction) - this will require some change on your code.

---

<div class="post-metadata">

**Author:** ![Sharma3007](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sharma3007/32/43414_2.png) [@Sharma3007](https://discuss.elastic.co/u/Sharma3007)\
**Post date:** [November 30, 2021, 4:57pm UTC](https://discuss.elastic.co/t/elastic-apm-not-working-with-net-wcf-service/290574/3 "2021-11-30T16:57:27Z")

</div>

Thanks @GregKalapos ,  
For quick reply.

The document part I have alredy tried, that is not working.But I'll verify both the approach again .our application hosted on seprate port. I mean web application on seperate port and wcf service on seperate port. So in which application we need to use that manual transaction code?

---

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [November 30, 2021, 5:00pm UTC](https://discuss.elastic.co/t/elastic-apm-not-working-with-net-wcf-service/290574/4 "2021-11-30T17:00:26Z")

</div>

Using a different port in itself should not really make a different from the agent's point of view, so that's fine.

> So in which application we need to use that manual transaction code?

This basically depends on what the agent captures out of the box - worst case the agent won't capture anything, in that case you'd need to manually instrument the code both in the client and in the server side. If you see part of the request showing up in Kibana out of the box - i.e. you see the server side and you don't see the client side which calls into the WCF service (this is a likely scenario) then you'd need to instrument the caller code.

---

<div class="post-metadata">

**Author:** ![Sharma3007](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sharma3007/32/43414_2.png) [@Sharma3007](https://discuss.elastic.co/u/Sharma3007)\
**Post date:** [December 1, 2021, 2:56pm UTC](https://discuss.elastic.co/t/elastic-apm-not-working-with-net-wcf-service/290574/5 "2021-12-01T14:56:51Z")

</div>

Hi @GregKalapos ,

Thanks for the update, I tried but still not working. In my case, my web application was deployed on the XXXX server & the service deployed on the YYYY server. I have configured the .net agent configuration in my web application only. And for web applications, it's working fine. but not able to get database related information which is a part of our service code. so just wanted to know that do we need to [configure.net](http://configure.net) agent configuration on the service side also? If yes then how to implement that on the service side because we don't have any global & startup files in our service.  
I am using below code in my global file in webapplication:

```
        var agentComponents = ElasticApmModule.CreateAgentComponents();
        Agent.Setup(agentComponents);`
        // subscribe to capture database spans to SQL server
        Agent.Subscribe(new SqlClientDiagnosticSubscriber());`

        // add transaction filter
        Agent.AddFilter((Elastic.Apm.Api.ITransaction t) =>
        {
            t.SetLabel("foo", "bar");
            return t;
        });
```

---

<div class="post-metadata">

**Author:** ![Sharma3007](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sharma3007/32/43414_2.png) [@Sharma3007](https://discuss.elastic.co/u/Sharma3007)\
**Post date:** [December 6, 2021, 3:59pm UTC](https://discuss.elastic.co/t/elastic-apm-not-working-with-net-wcf-service/290574/6 "2021-12-06T15:59:52Z")

</div>

Hi Team,

I am still waiting for the above response.

---

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [December 7, 2021, 2:37pm UTC](https://discuss.elastic.co/t/elastic-apm-not-working-with-net-wcf-service/290574/7 "2021-12-07T14:37:33Z")

</div>

@Sharma3007 your code snippet is fine, only thing to keep in mind if you go with the `Agent.Setup()` way of initialization is that you'll also need to enable auto instrumentation for any component you need - I see you do that for `SqlClientDiagnosticSubscriber` - so that should work, that'll capture DB calls to MS SQL Server through the `SqlClient` APIs.

To you question:

> so just wanted to know that do we need to [configure.net](http://configure.net) agent configuration on the service side also?

Yes - you'll need to enable the agent in every process in order to get out APM data from a given process.

> If yes then how to implement that on the service side because we don't have any global & startup files in our service.

You can use the exact same code-snippet you pasted - If I understand you correctly, then the DB call happens in the service, if so, then that's where you'd need the `Agent.Subscribe(new SqlClientDiagnosticSubscriber());`` - but if you have it on both side that's fine as well, it won't cause any trouble.

You can put the agent initializtion code basically anywhere - just make sure it runs only once - so typically it'd be in the `Main` method or in any other part of the startup code.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 28, 2021, 10:38am UTC](https://discuss.elastic.co/t/elastic-apm-not-working-with-net-wcf-service/290574/8 "2021-12-28T10:38:14Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
