【发布时间】:2015-05-20 11:01:37
【问题描述】:
我正在尝试通过 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 并且没有错误信息。如果服务不接电话,我觉得我会收到错误消息?
【问题讨论】:
-
您是否尝试使用一些工具来比较网络请求?例如。 telerik.com/fiddler
-
@ChrFin 实际上我只是在 Fiddler 中尝试过,并且使用正确的数据调用 C# 文件 show_thumbnail.aspx(调用服务)为我提供了想要的图像。编辑:意识到然后凭据是有效的,因为调用是从 C# 进行的。不确定如何在 Fiddler 中调用 SOAP 服务?
-
用 C# 调用一次,用 PHP 调用一次,然后比较通过网络发送的实际请求...
-
@ChrFin 哦,您的意思是从 localhost 拨打电话并分析请求?我会看看我能不能解决这个问题。调用来自不同的服务器 atm。
标签: c# php web-services soap networkcredentials