2009-11-12 21 views
0

我在网上搜索,但我没有得到它如何将自定义标题从flex发送到c#中的Web服务?

这是我的Flex代码:

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{ 

} 

,这是我的C#代码(老一套的默认值):

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

如何在c#中使用auth?

+0

你从哪里获得WebService类? – greggreg 2009-11-12 21:23:35

+0

本地计算机,用ASP.NET开发服务器调试visual studio – sergiogx 2009-11-12 23:47:29

回答

0

我已经找到了我会怎样,它张贴在这里,但如果你知道一个更好的办法,请告诉

Flex代码

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(); 


     } 

在C#我这样做

/// <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; 
    } 
+0

非常酷我一直在寻找这个帖子的感谢 – Mike 2012-07-19 14:05:30

+0

有没有办法通过用户名和密码? – Mike 2012-08-09 18:57:11

相关问题