相关疑难解决方法(0)

在C#中以编程方式创建WCF客户端的标头(wsse)部分

如何以编程方式在app #config中创建app.config服务设置的以下部分:

    <client>
  <endpoint address="https://someServiceUrl"
      binding="basicHttpBinding" bindingConfiguration="Contact"
      contract="ServiceReference.PostingWebService" name="PostingWebServicePort">
    <headers>
      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <wsse:UsernameToken>
          <wsse:Username>someusername</wsse:Username>
          <wsse:Password Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'>somepassword</wsse:Password>
        </wsse:UsernameToken>
      </wsse:Security>
    </headers>
  </endpoint>
</client>
Run Code Online (Sandbox Code Playgroud)

我已设法从c#生成绑定部分(上面未包含)和端点部分.我无法创建标题部分.

出现的错误是:(这是因为当我从c#生成所有内容时,我没有标题部分)

这项服务需要<wsse:Security>,但缺少.

header部分很重要,好像我从配置中排除它并使用config运行代码它也会产生上述错误.

我不想使用web.config/app.config.我必须从C#运行所有东西.(上面的app.config工作正常,但我想通过c#做同样的事情)

注意:下面的更新是基于以下提供的解决方案请通过以下解决方案的评论,以获得更好的理解

更新1 :(首先以编程方式使用BasicHttpBinding)

BasicHttpBinding binding = new BasicHttpBinding();
        binding.Name = "Contact";
        binding.CloseTimeout = TimeSpan.FromMinutes(1);
        binding.OpenTimeout = TimeSpan.FromMinutes(1);
        binding.ReceiveTimeout = TimeSpan.FromMinutes(10);
        binding.SendTimeout = TimeSpan.FromMinutes(1);
        binding.AllowCookies = false;
        binding.BypassProxyOnLocal = false;
        binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
        binding.MaxBufferSize = 524288;
        binding.MaxBufferPoolSize = 524288;
        binding.MaxReceivedMessageSize = 524288;
        binding.MessageEncoding = WSMessageEncoding.Text;
        binding.TextEncoding = System.Text.Encoding.UTF8;
        binding.TransferMode = TransferMode.Buffered;
        binding.UseDefaultWebProxy = …
Run Code Online (Sandbox Code Playgroud)

c# wcf ws-security wcf-security

10
推荐指数
2
解决办法
2万
查看次数

将WSSE SOAP标头添加到Web引用

我正在尝试将WSSE SOAP Header添加到我的服务调用中,但大多数示例都集中在WCF上.我没有使用WCF.我添加了一个Web引用(WSDL).

我尝试了各种方法但没有成功,比如 - 覆盖GetWebRequest方法:

    protected override System.Net.WebRequest GetWebRequest(Uri uri)
    {
        string user = "username";
        string pwd = "password";

        System.Net.WebRequest request = base.GetWebRequest(uri);

        string auth = string.Format("Basic {0}", Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(string.Format("{0}:{1}", user, pwd))));
        request.PreAuthenticate = true;
        request.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequested;
        request.Headers.Add(HttpRequestHeader.Authorization, auth);

        return request;
    }
Run Code Online (Sandbox Code Playgroud)

WSSE安全标题应类似于以下内容:

<Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <UsernameToken>
            <Username>username</Username>
            <Password>password</Password>
         </UsernameToken>
      </Security>
Run Code Online (Sandbox Code Playgroud)

提前谢谢了!亲切的问候,

soap web-reference c#-4.0

8
推荐指数
1
解决办法
3万
查看次数

如何将安全头添加到SOAP消息?

我正在尝试使用我们的C#App提供者使用Java编写的WebService.什么时候沟通,我得到这个:

WSDoAllReceiver:传入消息不包含必需的安全标头

从昨天开始,我正在尝试找出如何将安全头添加到SOAP消息中.

是的,我读过这篇文章(对于如何创建SOAP <wsse:Security>标题无能为力),但它没有用.

我环顾四周,这似乎是一个很有问题的问题.我想知道我是否可以在这里得到一些帮助,一些指针,一些代码,让我开始.

c# security web-services

7
推荐指数
1
解决办法
3万
查看次数

使用C#,WCF SOAP使用者使用WSSE纯文本身份验证?

我有一个WCF SOAP使用者,它由Visual Studio 2012从WSDL实现.WSDL由PeopleTools生成.基础对象是类型System.ServiceModel.ClientBase.

我需要SOAP请求类似于:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://xmlns.oracle.com/Enterprise/Tools/schemas">
    <soapenv:Header>
        <wsse:Security soap:mustUnderstand="1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <wsse:UsernameToken>
                <wsse:Username>[plain text username goes here]</wsse:Username>
                <wsse:Password>[plain text password goes here]</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
        <sch:InputParameters>
            <Last_Name>Aren</Last_Name>
            <First_Name>Cambre</First_Name>
        </sch:InputParameters>
    </soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)

这是我们最接近的地方:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
    <s:Header>
        <a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>
        <a:MessageID>urn:uuid:3cc3f2ca-c647-466c-b38b-f2423462c837</a:MessageID>
        <a:ReplyTo>
            <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
        </a:ReplyTo>
        <a:To s:mustUnderstand="1">http://[internal URL to soap listener]</a:To>
    </s:Header>
    <s:Body>
        <t:RequestSecurityToken Context="uuid-7db82975-2b22-4236-94a1-b3344a0bf04d-1" xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
            <t:TokenType>http://schemas.xmlsoap.org/ws/2005/02/sc/sct</t:TokenType>
            <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
            <t:KeySize>256</t:KeySize>
            <t:BinaryExchange ValueType=" http://schemas.xmlsoap.org/ws/2005/02/trust/tlsnego" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">FgMBAFoBAABWAwFQ9IhUFGUO6tCH+0baQ0n/3us//MMXzQA78Udm4xFj5gAAGAAvADUABQAKwBPAFMAJwAoAMgA4ABMABAEAABX/AQABAAAKAAYABAAXABgACwACAQA=</t:BinaryExchange>
        </t:RequestSecurityToken>
    </s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)

你会发现两个问题:

  • 没有纯文本WSSE凭据.传递服务不使用的二进制形式的凭据.
  • 身份验证Body不在Header.
  • 请求省略InputParameters.

这是必不可少的C#代码:

var …
Run Code Online (Sandbox Code Playgroud)

c# wcf ws-security asp.net-4.5 visual-studio-2012

7
推荐指数
1
解决办法
1万
查看次数