401 error when invoking asp.net service from c# -


i've been stuck on quite bit, keep getting 401 error when calling asp.net web service c# server side code. web service hosted on remote server, address config file (wrapper service). whenever call it, 401 error, though can invoke web service method web browser. here's code:

    private string getcode(string name)     {         xmldocument xmlresponse = new xmldocument();         string request = getrequestxml(name);         string response = executerequest(request);         if (response != "")         {             xmlresponse.loadxml(executerequest(request));             return xmlresponse.getelementsbytagname("roaming")[0].innertext;         }         else         {             return "error getting password";         }     }      private string getrequestxml(string username)     {         var sr = "<?xml version='1.0' encoding='utf-8'?>"+            "<soap:envelope xmlns:xsi='http://www.w3.org/2001/xmlschema-instance' xmlns:xsd='http://www.w3.org/2001/xmlschema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"+            "<soap:body>"+            "<getaccountinfo xmlns='http://tempuri.org/'>"+            "<loginname>"+username+"</loginname>"+            "</getaccountinfo>"+            "</soap:body>"+            "</soap:envelope>";         return sr;      }      private string executerequest(string soapstr)     {           httpwebrequest req = (httpwebrequest)webrequest.create(configurationmanager.appsettings["wraperservice"]);         req.headers.add("soapaction", "\"http://tempuri.org/" + "getaccountinfo" + "\"");         req.contenttype = "text/xml;charset=\"utf-8\"";         req.accept = "text/xml";         req.method = "post";          using (stream stm = req.getrequeststream())         {              using (streamwriter stmw = new streamwriter(stm))             {                 stmw.write(soapstr);             }         }          using (streamreader responsereader = new streamreader(req.getresponse().getresponsestream()))         {             string result = responsereader.readtoend();             //xdocument resultxml = xdocument.parse(result);             return result;         }     } 


Comments