views:

164

answers:

1

I've searched the web but i'm not getting it

This is my flex code:

private function callWS():void{
    var ws:WebService = new WebService();
    //changed this
    ws.addHeader(new SOAPHeader(new QName("uri","header1"),{AUTH:"bla"}));

    ws.loadWSDL("http://localhost:49548/test/WebService1.asmx?WSDL");

    ws.HelloWorld.addEventListener(ResultEvent.RESULT, onResult);
    ws.HelloWorld.addEventListener(FaultEvent.FAULT, onFault);
    ws.HelloWorld();
}

private function onResult(e:ResultEvent):void{

}
private function onFault(e:FaultEvent):void{

}

and this is my c# code (same old default values):

[WebMethod]
public string HelloWorld()
{
    //what to do here?
    return "Hello World";
}

how do I use auth in c#?

A: 

I've found out how, I'll post it here but if you know a better way please tell

flex code

private function callWS():void{
        var ws:WebService = new WebService();

        ws.addHeader(new SOAPHeader(new QName("http://tempuri.org/","Auth"),{usr:"woosh"}));

        ws.loadWSDL("http://localhost:49548/test/WebService1.asmx?WSDL");

        ws.HelloWorld.addEventListener(ResultEvent.RESULT, onResult);
        ws.HelloWorld.addEventListener(FaultEvent.FAULT, onFault);
        ws.HelloWorld();


       }

in c# I did this

    /// <summary>
    /// Summary description for WebService1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class WebService1 : System.Web.Services.WebService
    {
        public Auth auth;
        [WebMethod]
        [SoapHeader("auth")]
        public string HelloWorld()
        {

            return auth.usr;
        }
    }

    public class Auth : SoapHeader
    {
        public string usr;
    }
sergiogx