The HTTP request is unauthorized with client authentication scheme 'Anonymous'. consuming wsdl file

I am trying to consume a wsdl file and get a soap response but I always get the error

The HTTP request is unauthorized with client authentication scheme 'Anonymous'.The authentication header received from the server was 'Basic Realm’=myrealm. The remote server returned an error: (401) Unauthorized

Here is my wsdl file

 <?xml version="1.0" encoding="utf-8"?>
    <definitions xmlns:xsd="" xmlns:soap="" xmlns:tns="http://remittance_ws/rmt_ws.wsdl" name="rmt_ws" targetNamespace="http://remittance_ws/rmt_ws.wsdl" xmlns="">
            <xs:schema targetNamespace="http://remittance_ws/rmt_ws.wsdl" version="1.0" xmlns:xs="">
      <xs:element name="UnsupportedEncodingException" type="tns:UnsupportedEncodingException" />
      <xs:element name="remittanceXml" type="tns:remittanceXml" />
      <xs:element name="remittanceXmlResponse" type="tns:remittanceXmlResponse" />
      <xs:complexType name="remittanceXml">
          <xs:element minOccurs="0" name="inputXML" type="xs:string" />
      <xs:complexType name="remittanceXmlResponse">
          <xs:element minOccurs="0" name="return" type="xs:string" />
      <xs:complexType name="UnsupportedEncodingException">
          <xs:element minOccurs="0" name="message" type="xs:string" />
  <message name="remittanceXml">
    <part name="parameters" element="tns:remittanceXml" />
  <message name="remittanceXmlResponse">
    <part name="parameters" element="tns:remittanceXmlResponse" />
  <message name="UnsupportedEncodingException">
    <part name="fault" element="tns:UnsupportedEncodingException" />
  <portType name="rmt_ws">
    <operation name="remittanceXml">
      <input message="tns:remittanceXml" />
      <output message="tns:remittanceXmlResponse" />
      <fault name="UnsupportedEncodingException" message="tns:UnsupportedEncodingException" />
  <binding name="rmt_wsBinding" type="tns:rmt_ws">
    <soap:binding transport="" />
    <operation name="remittanceXml">
      <soap:operation soapAction="" />
        <soap:body use="literal" />
        <soap:body use="literal" />
      <fault name="UnsupportedEncodingException">
        <soap:fault use="literal" name="UnsupportedEncodingException" namespace="" />
  <service name="rmt_ws">
    <port name="rmt_ws" binding="tns:rmt_wsBinding">
      <soap:address location="" />

Here is the call I make

rmt_ws client = new rmt_wsClient();
                using (rmt_wsClient rmt_wsClient = new rmt_wsClient())

                    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

                    rmt_wsClient.ClientCredentials.UserName.UserName = UserName;
                    rmt_wsClient.ClientCredentials.UserName.Password = Password;

                    string messageToSend = "<wsTin>" + wsTin + "</wsTin><wsUser>" + wsUser + "</wsUser>" +
                        "<wsPswd>" + wsPswd + "</wsPswd><contain><bmrn>" + bmrn + "</bmrn><blrn>" + blrn +
                        "</blrn><bcnt>" + bcnt + "</bcnt><bafm>" + "bafm" + "</bafm></contain>";


                    string responsed = rmt_wsClient.remittanceXml(messageToSend);
                    rtn = responsed;

I saw in similar questions that there is something that I must change in app.config but everything I tried so far give me the same result.

Here is the part in my app.config in WcfClinet that I use now

        <binding name="rmt_wsBinding1" >
          <textMessageEncoding messageVersion="Soap11" />
          <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>
<endpoint address="" binding="customBinding"
        bindingConfiguration="rmt_wsBinding1" contract="IcisPayments.rmt_ws"
        name="rmt_ws" />

and here is the app.config in my main program that I make the call

<binding name ="rmt_wsBinding1">
          <security mode="TransportWithMessageCredential" >
       <message clientCredentialType="UserName" />
 <endpoint address="" binding="basicHttpBinding" bindingConfiguration="rmt_wsBinding1" contract="IcisPayments.rmt_ws" name="rmt_ws" />

I don't know if I must change the app.config in my WcfClient or there is another error. This is my first time I use wsdl files and soap messages. I don't have any details on how the server that I try to connect works.

1 answer

  • answered 2018-01-14 14:26 rippergr

    For anyone who has the same problem. The main problem is that even when I send the credentials it doesnt send them as header. I found the answer in my previous part of the question here thanks to H.G. Sandhagen