how do I send custom headers from flex to a web service in c#?
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";开发者_如何学Go
}
how do I use auth in c#?
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;
}
精彩评论