Hi,
I am trying to access an asmx service which requires basic authentication using .net core 2.0
Basically i did the following.
- Created a console application.
- Referenced the asmx in the console project using Add Connected Service -> Microsoft WCF Service Reference Provider.
- Used the following code to access the service. But while accessing the service, it is failing with Invalid Credentials. But when i used similar methodology to access the service using .net framework 4.6.1, it is working fine. Could you please help. Whether
i am doing anything wrong here in setting the header value?
<div>
static void Main(string[] args)</div> <div>
{</div> <div>
try</div> <div>
{</div> <div>
Console.WriteLine("Hello World!");</div> <div>
</div><div>
MySoapClient.EndpointConfiguration endpoint = new MySoapClient.EndpointConfiguration();</div> <div>
string credential = "muser" + ":" + "mypassword";</div> <div>
AddressHeader
authAddresHeader = AddressHeader.CreateAddressHeader("Authorization", string.Empty, "Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(credential)));</div> <div>
AddressHeader[] addressHeaders = new AddressHeader[1]
{ authAddresHeader };</div> <div>
System.ServiceModel.EndpointAddress endpointAddress = new System.ServiceModel.EndpointAddress(new Uri("https://my.domain.com/api/service1.asmx"), addressHeaders);</div> <div>
</div><div>
MySoapClient nppSoapClient = new MySoapClient(endpoint, endpointAddress);</div> <div>
</div> <div>
Task.Run(async () => { await nppSoapClient.ShowAsync(); }).GetAwaiter().GetResult();</div><div>
}</div> <div>
catch (Exception ex)</div> <div>
{</div> <div>
Console.WriteLine(ex.Message);</div> <div>
}</div> <div>
}</div>