wcf icon indicating copy to clipboard operation
wcf copied to clipboard

BasicHttpSecurity does not contain a constructor that takes 0 arguments

Open blair55 opened this issue 9 years ago • 5 comments

image

I've added a connected service following the steps in my previous issue (#2340). However, I'm now stuck at this point. Looking at the source code, none of the error descriptions make sense: BasicHttpSecurity specifies no other constructors, nor does it inherit from another class.

Am I doing something else stupid?

blair55 avatar Nov 06 '17 12:11 blair55

@blair55 the constructor of BasicHttpSecurity is not available on .NET Core. It's internal only. https://github.com/dotnet/wcf/blob/699e88523f1c589398cde22980f5eceea11e77f8/src/System.ServiceModel.Http/ref/System.ServiceModel.Http.cs#L25

From the way you are using it, it is not going to work either as message security is not supported on .NET Core (#8).

zhenlan avatar Nov 09 '17 02:11 zhenlan

We can make the constructor public but throw PNSE if using message security. https://github.com/dotnet/wcf/blob/699e88523f1c589398cde22980f5eceea11e77f8/src/System.ServiceModel.Http/ref/System.ServiceModel.Http.cs#L25

zhenlan avatar Nov 10 '17 19:11 zhenlan

Thanks for addressing. However I cannot progress without a message security supported (#8) as the SOAP service provider enforces use of the https protocol.

FYI, when I navigate to the constructor of the BasicHttpSecurity class, I see the following. This is the cause of my original confusion...

#region Assembly System.ServiceModel.Http, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.ServiceModel.Http.dll
#endregion

namespace System.ServiceModel
{
    public sealed class BasicHttpSecurity
    {
        public BasicHttpSecurityMode Mode { get; set; }
        public HttpTransportSecurity Transport { get; set; }
    }
}

blair55 avatar Nov 13 '17 11:11 blair55

@blair55, I heard your request for message security support loud and clear (btw, please upvote #8). Unfortunately, this needs some fundamental pieces from another team and this was not committed. This is why not much progress was made for this feature.

zhenlan avatar Nov 15 '17 21:11 zhenlan

When you provided a constructor for your class that takes arguments, the compiler no longer creates an empty constructor. Therefore, you cannot call an empty constructor because it does not exist. You would need to explicitly write the constructor that takes 0 arguments in your class's code. The constructor of the inheritance class needs to construct the base class first. since the base class does not have a default constructor (taking 0 arguments) and you are not using the non-default constructor you have now, this won't work. so either:

  • Add a default constructor to your base class, in which case the code of the descending class needs no change;

Or

  • Call the non-default constructor of the base class from the constructor of the descending class, in which case the base class needs no change.

markfilan avatar Apr 05 '22 05:04 markfilan