无法将SOAP标头发送到c#WS

我尝试连接到Web服务。 我成功地获得了'AppendChunk'功能,但没有标题,请有人告诉我我在做什么工作? 我必须发送的XML看起来像这样:

<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>

这是代码:require_once('/ root / nusoap-0.9.5 / lib / nusoap.php'); 函数GetFileContents($ filename){$ handle = fopen($ filename,“r”); $ contents = fread($ handle,filesize($ filename)); FCLOSE($处理); 返回$ 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);

你应该在发送之前编码你的文件,先添加函数

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

然后更改代码:

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

上一篇: Unable to send SOAP headers to c# WS

下一篇: How to extract text from word file .doc,docx,.xlsx,.pptx php