2

我正在尝试通过 PHP 访问网络服务。Web 服务返回一个带有 jpeg 图像的字节数组,然后将其显示在网页上。

今天,服务是通过 C# 调用访问的,就像这样

ImgService i = new ImgService();

凭据设置如下:

i.Credentials = new System.Net.NetworkCredential(username, password, domain);

访问网络服务:

byte[] result = null;

result = i.GetThumbNail(raceId, startNum, seasonId, height, width, true);
Response.ContentType = "image/jpeg";
Response.BinaryWrite(result);

该服务在 C# 中运行良好,但现在我需要通过 PHP 访问它,我得到的唯一图像是“missing.jpg”。我不确定这是否意味着凭据错误或其他错误,但我对凭据部分感到非常不确定。

这是没有任何凭据的 PHP 代码:

$client = new SoapClient("http://www.example.com/imgService.asmx?WSDL");
$result = $client->GetThumbNail($args['race'], $args['startnumber'], $args['year'], 0, 0, true);
$image_data = $result->GetThumbNailResult;
echo '<img src="data:image/jpeg;base64,'.base64_encode($image_data).'">';

我也尝试过使用这样的调用:

$headers = array(
                            'username'  =>  'user',
                            'password'  =>  'pass',
                            'domain'    =>  'domain'
                            );
$header = new SoapHeader("http://tempuri.org/", 'UserCredentials', $headers, false);
$client->__setSoapHeaders($header);
$result = $client->GetThumbNail(parameters);

两个版本都给了我相同的 missing.jpg 并且没有错误消息。如果服务不接听电话,我觉得我会收到错误消息?

4

1 回答 1

0

没有设法用旧的 Web 服务解决这个问题,所以我最终创建了一个新的 HttpHandler 做与旧服务相同的事情。那好吧...

于 2015-05-29T08:50:57.240 回答