question

Cris-1247 avatar image
0 Votes"
Cris-1247 asked Cris-1247 answered

.NET Core WCF Web Service with Cookies

Hi I have an app that calls a webservice and its been added as a reference but it needs to send the cookie information to be able to access the methods. Does anyone know how to do that? Thanks.

dotnet-aspnet-core-webapiwindows-wcf
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Cookies are an HTTP header.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cookie

The client app must add the cookie to the HTTP header when sending the request. What are you using to send the request?

By the way, it is far more common to send a bearer token.

0 Votes 0 ·

HI I am using HttpWebRequest. When adding reference in .NET framework it has System.Web.Services.Protocols with the CookieContainer. But .NET Core 3.1 doesnt. So how do I attach a Cookie before sending it to the service url?

0 Votes 0 ·
Cris-1247 avatar image
0 Votes"
Cris-1247 answered

I need to pass a session cookie to the web service before it allows me to use the method

using (WebServiceClient webservice = new WebServiceClient(WebServiceClient.EndpointConfiguration.WSHttpBinding_IWebService))
{
GetRequest inReq = new GetRequest();
GetResponse outRes = new GetResponse();

       inReq.Test1 = true;
       inReq.Test2 = true;

       outRes = webservice.GetContext(inReq);   .....


how do I insert Cookie? Thanks

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered AgaveJoe edited

you first need to read the cookie. from the server. you need a server url that will create and return the cookie. you then save the cookie and use in later calls.

passing the cookie is a little tricky:

https://stackoverflow.com/questions/59257689/asp-net-core-making-soap-api-request-with-wcf-client-how-to-add-a-cookie-header

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

am actually getting a different error now

The communication object, System.ServiceModel.ChannelFatory'1[IWebService], cannot be used for communication because it is in the Faulted state.

0 Votes 0 ·

The error can indicate the client is not properly handling the WCF connection when a fault is received. There are many possibilities for the what is causing the fault. You'll need to troubleshoot.

Turn on WCF tracing on the client and server.

Tracing and Message Logging

Then compare logs. Capture a good request/response so you know what good request/response looks like. You can also use a network trace tool or a proxy to capture the actual HTTP message. You'll want to make sure the HTTP request is formatted properly. Again, it is helpful if you have a good HTTP request for comparison.


0 Votes 0 ·
Cris-1247 avatar image
0 Votes"
Cris-1247 answered

I am still getting errors intermittently

service is unavailable This could be because the service is too busy or because no endpoint was found listening at the specified address...

I think it could be because of maxConcurrentSessions or maxConcurrentInstances

Anyone know how to set this in appsettings.json? Thanks I appreciate it

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.