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

时间:2013-11-07 07:32:01

标签: c# php

我尝试连接到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( '/根/的NuSOAP-0.9.5 / LIB / nusoap.php');         function GetFileContents($ filename){           $ handle = fopen($ filename,“r”);           $ contents = fread($ handle,filesize($ filename));           FCLOSE($处理);           返回$ contents;         }         $ parameters = array(“stream”=&gt; 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);

1 个答案:

答案 0 :(得分:0)

您应该在发送之前对文件进行编码,首先添加功能

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