从PHP调用C#SOAP Web服务会生成错误的数据


Calling a C# SOAP webservice from PHP generates bad data

我正在开发一个新网站,我需要调用由"分包商"提供的网络服务

WDSL的一部分:

<s:element name="Send_Question">
   <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="spm" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="fylke" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="username" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
        <s:element minOccurs="1" maxOccurs="1" name="errorCode" type="s:int"/>
        <s:element minOccurs="0" maxOccurs="1" name="errorDescription" type="s:string"/>
      </s:sequence>
    </s:complexType>
 </s:element>
 <s:element name="Send_QuestionResponse">
    <s:complexType>
      <s:sequence>
         <s:element minOccurs="0" maxOccurs="1" name="Send_QuestionResult">
             <s:complexType mixed="true">
                <s:sequence>
                   <s:any/>
                </s:sequence>
              </s:complexType>
          </s:element>
       <s:element minOccurs="1" maxOccurs="1" name="errorCode" type="s:int"/>
       <s:element minOccurs="0" maxOccurs="1" name="errorDescription" type="s:string"/>
     </s:sequence>
   </s:complexType>
  </s:element>
POST /WebService/WebService.asmx HTTP/1.1
Host: domain.no
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "https://domain/WebService/Send_Question"
<?xml version="1.0" encoding="utf-8"?>
<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>
    <Send_Question xmlns="https://domain/WebService/">
      <spm>string</spm>
      <fylke>string</fylke>
      <username>string</username>
      <password>string</password>
      <errorCode>int</errorCode>
      <errorDescription>string</errorDescription>
    </Send_Question>
  </soap:Body>
</soap:Envelope>

我尝试了几种不同的方法来让它在这里发挥作用,这似乎是目前最有效的方法。

$client = new SoapClient("https://domain.no/WebService/WebService.asmx?WSDL", array('trace' => 1));

$UsrName = 'someUserName';
$PassWd = 'password';
$errorCode = 0;
$errorDescription = '';
try{
$params = array(
            'spm' => 'Dette er en hardkodet test', //$Sporsmal;
            'fylke' => 'hardkodet fylke', //$fylke;
            'username' => md5($UsrName),
            'password' => md5($PassWd),     
            'errorCode' => $errorCode,
            'errorDescription' => $errorDescription
        );
         $result  = $client->Send_Question($params);
         return $result;
}catch (SoapFault $fault){
        echo '<br/>En feil oppstod<br/>';
        echo $client->__getLastRequest() .'<br/>';
        echo $fault->faultcode . ' - ' . $fault->faultstring . ' - ' .$fault->detail;
    }

但我得到的只是soap:Server-Server无法处理请求。--->错误数据-根据过去的经验,我猜问题出在"错误代码"answers"错误描述"上

$client->__getLastRequest()转储没有xml或"SOAP信封"的原始walue

好的,所以这是不同事物的小混合。并且不会厌倦好的错误消息。

我的代码最终如下所示。

try{
         $Send_Question = $client->Send_Question;
         $Send_Question->spm = $Sporsmal;
         $Send_Question->fylke = $fylke;
         $Send_Question->username = $usernm;
         $Send_Question->password = $passwd;
         $Send_Question->errorCode = &$errorCode;
         $Send_Question->errorDescription = &$errorDescription;
         $result = $client->Send_Question($Send_Question);

        return $result;
    }catch (SoapFault $fault){
        echo '<br/>error ocoured<br/>';
        //echo '<br/>' . $client->__getLastRequestHeaders() . '<br/>';
        //echo '<strong>Request:'n</strong><br/>' . $client->__getLastRequest() .''n<br/>';
        //echo '<strong>Response:'n</strong><br/>' . $client->__getLastResponse() .''n<br/>';
        //echo '<strong>Feilmelding fra "SoapFault"</strong> ' . $fault->faultcode . ' - ' . $fault->faultstring . ' - ' .$fault->detail;
    }

但主要问题是用户名和密码没有正确加密。需要MD5和三重DES。