c# - 找不到 WS-Security header

标签 c# asp.net wcf

我正在尝试使用演示网址如下的服务

[https://demo.unicommerce.com/services/soap/uniware13.wsdl?facility=01][1]

当我添加此服务并尝试在我的代码中使用它时,如下所示

using abc;
public partial class unicommerce : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        unicommerce u = new unicommerce();

        UnicommerceClient us = new UnicommerceClient();


        Customer c=new Customer ();
        PartyAddress pa=new PartyAddress ();
        pa.StateCode="25";
        pa.Pincode="302017";
        c.BillingAddress=pa;
        PartyContact p=new PartyContact ();

        c.Contact=p;
        c.CSTNumber="123";
        c.CustomerCode="ABC";
        c.Name="example";
        c.PAN="CYKPS7842";
        c.Website="http://mywebsite.in";

        CreateCustomerRequest cr = new CreateCustomerRequest();
        cr.Customer = c;
        us.CreateCustomer(cr);

    }
}

它的抛出错误

No WS-Security header found

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ServiceModel.FaultException: No WS-Security header found
  [1]: https://demo.unicommerce.com/services/soap/uniware13.wsdl?facility=01

我问过做这个服务的人,他告诉我这个服务是用java代码快速创建的。

据我所知,这个错误与用户名和密码(身份验证)有关,但不知道我应该在哪里传递这些凭据。

最佳答案

您可以使用 Microsoft.Web.Services2 中的标准 .Net WSS 实现

using Microsoft.Web.Services2.Security.Tokens;
using Microsoft.Web.Services2.Security.Utility;

UsernameToken token = new UsernameToken(username, password, passwordOption.SendHashed);          

Microsoft.Web.Services2.Security.Utility.Timestamp ts = new Timestamp();

XmlDocument doc = new XmlDocument();

XmlElement token = token.GetXml(doc);
XmlElement timestamp = ts.GetXml(doc);

string stoken = token.InnerXml;
string stimestamp = ts.InnerXml;

等等,完美无缺。

Microsoft.Web.Services2.dll 可以在这里找到:

http://www.microsoft.com/downloads/details.aspx?FamilyId=FC5F06C5-821F-41D3-A4FE-6C7B56423841&displaylang=en

关于c# - 找不到 WS-Security header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17161328/

相关文章:

c# - 数据表添加数据行时出现错误[]

c# - ASP.NET:获取TreeNode的容器TreeView

asp.net - web.config 的位置元素中的多个路径

c# - 无法调用服务,WCF 测试客户端?

wcf - ASP.net Web 服务与 WCF

.net - WCF 和接口(interface)继承 - 这是一件可怕的事情吗?

c# - 林克/C# : How to split List into variable length chunks based on list item information?

c# - 缺少 System.web.mvc

javascript - 母版页和内容页上的多个 ScriptManager

c# - IO 异常 (XML) - 该进程无法访问该文件,因为该文件已被另一个进程使用