5 c# sql-server soap visual-studio
我正在尝试使用SOAP头来允许SQL身份验证,同时访问通过HTTP端点在我的SQL 2005框上发布的Web服务.在端点上,我设置了Authentication =(Basic),Ports =(SSL)和LOGIN_TYPE = MIXED.我能够生成WSDL并使用域凭据在VS中使用它.但是,当我尝试实现SOAP标头以允许SQL身份验证时,我遇到了问题.我已经关注了MS BOL(http://msdn.microsoft.com/en-us/library/ms189619 ( SQL.90 ) .aspx),但出于某种原因,我没有发送SOAP标头.我已经通过使用fiddler(http://www.fiddler2.com/fiddler2/)来验证这一点,以捕获我的https消息并查看它们.任何帮助将不胜感激.包括我一直在使用的代码(名称已被更改以保护无辜者)
namespace ConsoleApplication.WebService
{
class Program
{
static void Main(string[] args)
{
//Prevents error due to self signed cert
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
Stuff stuff = new Stuff();
stuff.DoSomthing();
}
}
public class Stuff
{
[System.Web.Services.Protocols.SoapHeaderAttribute("sqlSecurity")]
public int DoSomthing()
{
Webservice ws = new Webservice();
CredentialCache myCreds = new CredentialCache();
myCreds.Add(new Uri(ws.Url), "Basic", new NetworkCredential("netaccount", "netpass", "domain"));
ws.Credentials = myCreds;
ws.sqlSecurity = new SqlSoapHeader.Security();
ws.sqlSecurity.Username = "sqluser";
ws.sqlSecurity.Password = "sqlpass";
try
{
ws.SelectUserAccountByUserName("someuser");
}
catch (SoapException ex)
{
string txterror = ex.Detail.InnerText;
return 0;
}
return 1;
}
}
public partial class Webservice
{
public SqlSoapHeader.Security sqlSecurity;
}
}
Run Code Online (Sandbox Code Playgroud)
此代码使用SqlSoapHeader类,如上面的BOL参考中所述.
由于"netaccount"用户无权执行存储过程,因此在调用ws.SelectUserAccountByUserName()时出现"执行权限被拒绝"时出错.但同样,这是因为根据soap消息,没有传递sqluser信息的标头.