PHP 中的 C# NetworkCredential

标签 c# php web-services soap networkcredentials

我正在尝试通过 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 并且没有错误消息。如果服务不接受调用,我觉得我会出错?

最佳答案

旧的 web 服务无法解决这个问题,所以我最终创建了一个新的 HttpHandler 来做旧服务所做的同样的事情。 好吧……

关于PHP 中的 C# NetworkCredential,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30347769/

相关文章:

c# - Xamarin.Forms - C# 代码中的 View 到 View 绑定(bind)?

c# - 将 WP8 升级到 Silverlight WP8.1,程序集问题

php - 如何在查询语句中格式化日期?

php - 在 cloud9 环境中运行自定义网络服务器并从外部世界访问它

c# - 未检测到 Web 服务?

node.js - Node : serving secure (wss://) and insecure (ws://) connections with the same server

android - "org.xmlpull.v1.XmlPullParserException: expected: START_TAG"错误

c# - 我如何重写文件而不是使用 StreamWriter 和文件流附加

c# - 在 C# 中将任意类型实例写入 MemoryStream

php - 如何在 DOM 中 php 和 javascript 之间共享数据?