2013-08-07 43 views
4

我试图通过https对C#上编写的web服务执行soap请求。服务器使用自签名证书。通过https与自签名证书通过cURL执行soap请求

在使用SoapClient多次尝试失败后,我决定使用纯粹的cURL来执行请求。

我的代码:

<?php 
header('Content-Type: text/plain; charset=utf-8'); 

$url  = 'https://ip:8443/ServiceName'; 
$admin = 'login'; 
$password = 'haShedPassw0rdHere'; 

$post  = 
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
     // Soap service params xml 
    </soap:Body> 
</soap:Envelope>'; 

$headers = array(    
    'Content-type: text/xml;charset="utf-8"', 
    'Accept: text/xml', 
    'Cache-Control: no-cache', 
    'Pragma: no-cache', 
    'SOAPAction: https://ip:8443/ServiceName', 
    'Content-length: ' . strlen($post), 
); 

$curl = curl_init(); 

$options = array(
    CURLOPT_URL => $url, 
    CURLOPT_HTTPHEADER => $headers, 
    CURLOPT_HTTPAUTH => CURLAUTH_ANY, 
    CURLOPT_USERPWD => $admin . ':' . $password, 
    CURLOPT_SSL_VERIFYPEER => false, 
    CURLOPT_SSL_VERIFYHOST => false, 
    CURLOPT_POST => true, 
    CURLOPT_POSTFIELDS => $post, 
    CURLOPT_RETURNTRANSFER => true, 
    CURLOPT_HEADER   => false, 
    CURLOPT_FOLLOWLOCATION => true, 
    CURLOPT_ENCODING  => '', 
    CURLOPT_AUTOREFERER => true, 
    CURLOPT_CONNECTTIMEOUT => 120, 
    CURLOPT_TIMEOUT  => 120, 
    CURLOPT_MAXREDIRS  => 10 
); 

curl_setopt_array($curl, $options); 

var_dump($response = curl_exec($curl)); 
?> 

响应:

string(370) " 
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Body> 
     <s:Fault> 
      <faultcode xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
       a:InvalidSecurity 
      </faultcode> 
      <faultstring xml:lang="ru-RU"> 
       Ошибка при проверке безопасности сообщения. 
      </faultstring> 
     </s:Fault> 
    </s:Body> 
</s:Envelope>" 

其中:

Ошибкаприпроверкебезопасностисообщения。

意思是这样的:

通信安全检查错误。

有什么我想:

  1. POST request with a self-signed certificate
  2. How to consume a WCF Web Service that uses custom username validation with a PHP page?
  3. Php SoapClient stream_context option
  4. SOAP authentication with PHP
  5. How can I send SOAP XML via Curl and PHP?

其中更多。

问题:我做错了什么?

问候。

P.S:测试与PHP 5.3PHP 5.4.14PHP 5.5.1。结果是一样的。


UPDv1:

C#源代码,以服务支持团队提供:

private void Button_SetData_Click(object sender, EventArgs e) 
{ 
    eLeed.WebServiceClient client = 
     new eLeed.WebServiceClient(); 
    client.ClientCredentials.UserName.UserName = "login"; 
    client.ClientCredentials.UserName.Password = "haShedPassw0rdHere"; 
    Stream input = null; 
    input = GetQuery("ServiceMethod", TextBox_Command.Text); 
    XmlDocument response = new XmlDocument(); 
    response.PreserveWhitespace = true; 
    response.Load(client.SetDataContractor(input)); 
    ExeResponse(response); 
    input.Close(); 
    client.Close(); 
} 

那么,这个按钮是实际工作。但是如何在cURL中执行类似于php的操作?特别是,如何通过这两条线:

client.ClientCredentials.UserName.UserName = "login"; 
client.ClientCredentials.UserName.Password = "haShedPassw0rdHere"; 

因此,它不应该像返回“无效凭证”什么消息?

+0

你能翻译俄语错误信息 – DevZer0

+0

@ DevZer0对不起。刚注意到。 – BlitZ

+0

soap api是否规定了某种形式的安全机制,比如某种形式的标题中的主体哈希?如果您熟悉亚马逊的'MWS'则需要使用私钥创建签名,使用身体的所有有效载荷作为头部的一部分传入 – DevZer0

回答

1

错误似乎不是在客户端,而是在服务器端。服务器说一些安全检查失败。如果这是一个客户端错误,您将只能通过cURL得到一个错误。你会得到一个XML答案。

你应该看看服务器端。

+0

谢谢。不幸的是,服务器和网络服务不在我的控制之下。但我期待着联系支持。正如他们之前所说,他们“不知道它有什么问题”。 – BlitZ

+0

从新数据看来,它不是服务器,而是脚本。您不会将必要的信息发送到服务器。它需要一些类似的auf认证。不可能说出验证如何与提供的信息一起工作。 –

+0

那么,这是所有支持提供的信息。我也不知道完整的验证算法。但是,正如他们(和你)提到的那样,这可能是他们的问题。 – BlitZ

相关问题