Unable to send SOAP headers to c# WS

i try to connect to web service. i success to get to the function 'AppendChunk', but with out headers, please Someone, tell me what i am doing worng? the xml i have to send look like that:

<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:Header>
    <WSCredential xmlns="http://cellact.com/">
      <Username>string</Username>
      <Password>string</Password>
      <Company>string</Company>
    </WSCredential>
  </soap:Header>
  <soap:Body>
    <AppendChunk xmlns="http://cellact.com/">
      <FileName>string</FileName>
      <buffer>base64Binary</buffer>
      <Offset>long</Offset>
    </AppendChunk>
  </soap:Body>
</soap:Envelope>

this is the code: require_once('/root/nusoap-0.9.5/lib/nusoap.php'); function GetFileContents( $filename ) { $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); return $contents; } $parameters = array("stream" => GetFileContents("bookSmall.csv"));

    $client = new nusoap_client('http://cellactprolocal.net/mews/WSExt2.asmx?wsdl',true);
    $params = array(
        'FileName' => "book2.csv",
        'buffer' => $parameters,
        'Offset' => 0
    );                      
    $ns = "http://cellact.com";     

    $headers = "<WSCredential ><ns1:Username xmlns:ns1="$ns">xxx</ns1:Username>
                <ns2:Password xmlns:ns2="$ns">xxx/</ns2:Password>
                <ns3:Company xmlns:ns3="$ns">xxx</ns3:Company>
                </WSCredential >";

    $client->setHeaders($headers);
    $result = $client->call('AppendChunk', $params, $ns);
    print_r($result);

You should encode your file before sending, first add function

function GetFileContents( $filename ) {
    $handle = fopen($filename, "r");
    $contents = fread($handle, filesize($filename));
    fclose($handle); 
    return $contents;
} 

Then change in the code :

$decodeContent   = base64_encode(GetFileContents("your file name")); 
$params = array(
    'FileName' => "test.csv",
    'buffer' => $decodeContent,
    'Offset' => 0
);
链接地址: http://www.djcxy.com/p/45520.html

上一篇: 从谷歌驱动器下载的文件选择器被损坏

下一篇: 无法将SOAP标头发送到c#WS