Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I have this error System.ServiceModel.Security.MessageSecurityException

For what I read and understood, this happens when I’m not sending the authentication.

But I tried to send it in two ways:

string userN = "username";
string _pasw = "password";
BasicHttpBinding binding = new BasicHttpBinding();
Endpoint wsdl = new Endpoint("MyEndpoint");


SoapClient client = new SoapClient(binding, wsdl);
client.ClientCredentials.UserName.UserName = userN;
client.ClientCredentials.UserName.Password = _pasw;
await client.OpenAsync();

And:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

HttpClient request = new HttpClient();
var svcCredentianls = Encoding.ASCII.GetBytes(userN + ":" + _pasw);
request.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(svcCredentianls));

But in one way or another I’m having this error:

System.ServiceModel.Security.MessageSecurityException: ‘The HTTP request is not authorized with the "Anonymous" client authentication scheme. The authentication header received from the server was "Basic realm="SAP NetWeaver Application Server [PRD/400]"".’

Where I’m wrong or what I’m missing?

>Solution :

I believe the problem is with yours binding configuration in your web.config.
Please check security node.

<security mode="Transport">
  <transport clientCredentialType="Basic" proxyCredentialType="Basic" realm="" />
</security>

Below you can find my working example:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="Transport">
                    <transport clientCredentialType="Basic" proxyCredentialType="Basic" realm="" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="https://pc:8080/Service.svc/SslService" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService"
            name="BasicHttpBinding_IService" />
    </client>
</system.serviceModel>

In case if you don’t use web.config configuration you can try to adjust your BasicHttpBinding creation code with:

BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.Transport;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading