SOAP 标头:Flex 和 C# 之间的通信受到保护
我正在使用 Flex、Webservices 和 C#,我希望通过 SOAP 保护对我的 Web 服务的访问。
我花了 2 天的时间来解决这个问题:
我的 asmx 文件,其中我描述了我的 webmethod:
public ServiceAuthHeader CustomSoapHeader = new ServiceAuthHeader();
[SoapHeader("CustomSoapHeader")]
[WebMethod(Description = "Return Somme")]
public int getTotal(int x, int y)
{
ServiceAuthHeaderValidation.Validate(CustomSoapHeader);
var total = x+y;
return total;
}
public class ServiceAuthHeader : SoapHeader
{
// SoapHeader for authentication
public string Username;
public string Password;
}
然后我写了一个类来检查是否 SOAP 标头的内容是 好的。
public class ServiceAuthHeaderValidation
{
[SoapHeader("soapHeader")]
[WebMethod(Description = "Check Header")]
public ServiceAuthHeader Validate(ServiceAuthHeader soapHeader)
{
if (soapHeader == null)
{
throw new NullReferenceException("No soap header was specified.");
}
if (soapHeader.Username ==null)
{
Console.WriteLine(soapHeader.Username);
throw new NullReferenceException("Username was not supplied for authentication in SoapHeader!");
}
if (soapHeader.Password == null)
{
throw new NullReferenceException("Password was not supplied for authentication in SoapHeader.");
}
if (soapHeader.Username != "JOE") || soapHeader.Password != "JOE")
{
throw new Exception("Please pass the proper username and password for this service.");
}
return true;
}
到目前为止
我认为我是对的。
但是,当我想在 Flex 中实现它时:
var q1:QName=new QName("http://localhost:59399/Service1.asmx?wsdl", "Header1");
header1=new SOAPHeader(q1, {String:"JOE",String JOE});
_serviceControl.addHeader(header1);
我的用户名上出现 NullReferenceException,这似乎没有提供。
我的网络服务可以正常工作,除非我尝试实现:
ServiceAuthHeaderValidation.Validate(CustomSoapHeader);
有人可以回复我以了解缺少什么吗?或者是我的错误..
谢谢您的宝贵时间。
到目前为止,StackoverFlow 通过阅读不同的答案对我帮助很大,但今天我仍然坚持下去。如果有人可以帮忙的话。
I am working with Flex, Webservices and C# and I would like to secure the access on my web services through SOAP.
I spent 2 days on this problem:
My asmx file where i describe my webmethod:
public ServiceAuthHeader CustomSoapHeader = new ServiceAuthHeader();
[SoapHeader("CustomSoapHeader")]
[WebMethod(Description = "Return Somme")]
public int getTotal(int x, int y)
{
ServiceAuthHeaderValidation.Validate(CustomSoapHeader);
var total = x+y;
return total;
}
public class ServiceAuthHeader : SoapHeader
{
// SoapHeader for authentication
public string Username;
public string Password;
}
Then I wrote a class to check if the
content of SOAP Header is
good.
public class ServiceAuthHeaderValidation
{
[SoapHeader("soapHeader")]
[WebMethod(Description = "Check Header")]
public ServiceAuthHeader Validate(ServiceAuthHeader soapHeader)
{
if (soapHeader == null)
{
throw new NullReferenceException("No soap header was specified.");
}
if (soapHeader.Username ==null)
{
Console.WriteLine(soapHeader.Username);
throw new NullReferenceException("Username was not supplied for authentication in SoapHeader!");
}
if (soapHeader.Password == null)
{
throw new NullReferenceException("Password was not supplied for authentication in SoapHeader.");
}
if (soapHeader.Username != "JOE") || soapHeader.Password != "JOE")
{
throw new Exception("Please pass the proper username and password for this service.");
}
return true;
}
}
So far I think I'm right.
But while i want to implement it in Flex:
var q1:QName=new QName("http://localhost:59399/Service1.asmx?wsdl", "Header1");
header1=new SOAPHeader(q1, {String:"JOE",String JOE});
_serviceControl.addHeader(header1);
I get a NullReferenceException on my username, which seems to be not supply.
My Webservice works, except when I try to implement:
ServiceAuthHeaderValidation.Validate(CustomSoapHeader);
Could someone reply me in order to know what is missing ? or my mistake..
THank you for your time.
So far StackoverFlow helped me a lot by reading different answers but today I stay stuck on it. If someone can help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只使用自定义 XML:
请记住,在 E4X 定义中使用 {}看起来是更新的绑定,但事实并非如此。
I just use a custom XML:
Keep in mind that using {} inside an E4X definition looks like a binding that updates, it's not.
非常感谢,Sophistifunk
我终于在生成的 AS 子类中添加了。
但是当我们通过 Flex 4 的 IDE 实现一个新的 WebService 时,一切都是在 AS 中生成的。
但管理标题的方式真的很糟糕。
这应该自动负责安全标头。我的意思是创建一个可从 mxml 应用程序绑定的函数 setLogin 或 setpassword 。
反正。
如果有人知道如何通过更好的方式来管理 SOAP 标头。
Thanks a lot, Sophistifunk
I finally added in my generated AS sub class.
But when we implement a new WebService in Flex 4 through its IDE, everything is generated in AS.
But The way to manage the header sucks really.
That should take in charge automatically the security Header.. I mean create a function setLogin or setpassword bindable from or mxml application.
Anyway.
If someone know a way to take in charge the Header of SOAP through a better way.