Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用.net webservices wse或wcf创建安全的SOAP主体?_C#_.net_Wcf_Security_Soap - Fatal编程技术网

C# 如何使用.net webservices wse或wcf创建安全的SOAP主体?

C# 如何使用.net webservices wse或wcf创建安全的SOAP主体?,c#,.net,wcf,security,soap,C#,.net,Wcf,Security,Soap,目前,我正在使用Java web服务访问.NEt。这里我使用WSE3.0来使用Java安全web服务。但我得到了一个错误: “引发异常:无法检索引用的安全令牌” 在比较java SOAP请求和.NET SOAP请求之后,我发现我发送的.NET SOAP头是正确的,但发送的正文是错误的。有谁能帮我发送安全机构请求表.net客户端吗 下面,我给出了Java和.Net SOAP XML数据: .Net请求XML SOAP正文(我正在发送) <soap:Body xmlns:wsu="

目前,我正在使用Java web服务访问.NEt。这里我使用WSE3.0来使用Java安全web服务。但我得到了一个错误:

“引发异常:无法检索引用的安全令牌”

在比较java SOAP请求和.NET SOAP请求之后,我发现我发送的.NET SOAP头是正确的,但发送的正文是错误的。有谁能帮我发送安全机构请求表.net客户端吗

下面,我给出了Java和.Net SOAP XML数据:

.Net请求XML SOAP正文(我正在发送)

      <soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-2">
<xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="ED-5" Type="http://www.w3.org/2001/04/xmlenc#Content">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">

<wsse:SecurityTokenReference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd" wsse11:TokenType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKey">
<wsse:Reference URI="#EK-7FBF3DBE856BC8B2BC14527661038314"/>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
<xenc:CipherData>
<xenc:CipherValue>SQ0nnx45EPDL5uoFRzeTjJy6+FhaCZTK/3LRz5DrPM4qAQ2JzARNiLmuj61YSHd6nOMVy1QmPCqH5gG6PIIN8x47r10fzOkuisxpcOaUdnFL3bY55AvfyL6fUbSfcp+fl3qw6SAB3QF0AR1thqpfKBttBv8b7GxbpApCZg6TWaw8nD7G7dVmtdpDBJN7uQSQJu5ibdBGLzbVoF9YtliYH1mbdswL4KVJtZKUl2UAQqDtbxgXAkKtNwNyq4pt7N+HVhX00mZMxiTE0IyRyfgQhwp6afsTvsGVmdKxcpWtRoOFmmIHhrTeXJal/jJAI84mmg5EV44TJezFFbEyqsL+vhhR/N6oITaa
</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
</soap:Body>

UO32nmFhQZ4JBNuWk6xTz20FpjfPWQqr1F5zqOf7uQ6hBJzfndGAJvb/l/MGT0X7P2ZTIEENJ51ZDYKDZRQ1AX3SCJYZACX6SUEMUVMMAVGTJ8DJPQKA7T3XDKWPGFVLDMC1AM1B+E7SXDF9RIINV+JPYHFF54M3ZAEYVPQLVV3RPVYA2LC/LeHVYwM/EP6X5F9NZ50UASBHIA==
JAVA请求的XML SOAP正文(应来自JAVA web服务器)

      <soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-2">
<xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="ED-5" Type="http://www.w3.org/2001/04/xmlenc#Content">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">

<wsse:SecurityTokenReference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd" wsse11:TokenType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKey">
<wsse:Reference URI="#EK-7FBF3DBE856BC8B2BC14527661038314"/>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
<xenc:CipherData>
<xenc:CipherValue>SQ0nnx45EPDL5uoFRzeTjJy6+FhaCZTK/3LRz5DrPM4qAQ2JzARNiLmuj61YSHd6nOMVy1QmPCqH5gG6PIIN8x47r10fzOkuisxpcOaUdnFL3bY55AvfyL6fUbSfcp+fl3qw6SAB3QF0AR1thqpfKBttBv8b7GxbpApCZg6TWaw8nD7G7dVmtdpDBJN7uQSQJu5ibdBGLzbVoF9YtliYH1mbdswL4KVJtZKUl2UAQqDtbxgXAkKtNwNyq4pt7N+HVhX00mZMxiTE0IyRyfgQhwp6afsTvsGVmdKxcpWtRoOFmmIHhrTeXJal/jJAI84mmg5EV44TJezFFbEyqsL+vhhR/N6oITaa
</xenc:CipherValue>
</xenc:CipherData>
</xenc:EncryptedData>
</soap:Body>

2.2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 TJEZFFBEYQSL+vhhR/N6oI塔阿

您知道如何从.Net web服务或WCF向服务器发送与Java相同的请求吗?

您必须这样做才能将X.509集成到web服务客户端

       public void MyWebServiceClient()
       {
            using (var client = new MyWebService())
            {
                try
                {
                    //calls the web service
                    client.Url = //Your server EndpointUri;

                    //assign cert
                    ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
                    string certificatePath = //certificate path
                    string certificatePassword = //certificate password
                    X509Certificate2 cert = new X509Certificate2(certificatePath, certificatePassword, X509KeyStorageFlags.MachineKeySet);
                    client.ClientCertificates.Add(cert);

                    //var result = client.WebServiceCall(your input);
                }
                catch (Exception ex)
                {
                    throw new Exception("Error " + ex.Message);
                }
            }
        }


    public bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
    {            
        // accept all certificates
        return true;
    }

你有X.509证书吗?通常它以pfx文件的形式出现?是的,我在我的代码中使用x.509证书。我们希望看到您的客户端代码。看起来它找不到证书或者您使用了错误的证书。您好,kosala w感谢您的回复我使用的是正确的证书,即clientinvoke.pfx我从服务器获得了正确的响应,但出现了一些错误“referece token丢失”…所以我只是在输入跟踪文件中检查服务器的整个sopa响应,我发现我不知道如何在side body元素中传递这两个标记…?正如我所说的,我们需要查看客户端调用。您可能根本没有将证书包括在web服务呼叫中。hi kosala w感谢您的建议我在这里使用windows窗体应用程序我的代码如下