php连接wcf时报错

lokiice 2009-08-14 11:22:09
wcf程序是基本的模板程序,
能够正常连接名输出wcf服务的信息,但是调用方法的时候就出错

php代码
<?php


echo "WCF Test\r\n\r\n";


$ws = "http://localhost:8080/service1?wsdl";
$client = new SoapClient($ws,array(
'soap_version' => SOAP_1_1,
'trace' => 1,
'exceptions' => 1
));


echo('<pre>');
var_dump($client->__getFunctions());
echo('</pre>');

echo("SOAP服务器提供的Type:");

echo('<pre>');
var_dump($client->__getTypes());
echo('</pre>');



echo("执行sayHello的结果: <br />");

try {
$parameters=array('text'=>'5do8');
$username = $client->sayHello($parameters);
} catch (SoapFault $fault){
echo "Fault! code:",$fault->faultcode,", string: ",$fault->faultstring;
}
//echo(htmlspecialchars($client->__getLastRequest()));
echo('<pre>');
if(is_array($username))
{
foreach($username as $key => $val) {
echo($val);
}
}
echo('</pre>');


?>


页面输出
WCF Test
array(1) {
[0]=>
string(47) "sayHelloResponse sayHello(sayHello $parameters)"
}
SOAP服务器提供的Type:
array(5) {
[0]=>
string(33) "struct sayHello {
string text;
}"
[1]=>
string(51) "struct sayHelloResponse {
string sayHelloResult;
}"
[2]=>
string(8) "int char"
[3]=>
string(17) "duration duration"
[4]=>
string(11) "string guid"
}
执行sayHello的结果:
Fault! code:HTTP, string: Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'.
...全文
331 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lokiice 2009-08-19
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 lgzxz999 的回复:]
不知道soap+xml是什么
当方法是有的,先全文件夹查找"'text/xml; charset=utf-8'",然后换成'application/soap+xml; charset=utf-8'试试看
[/Quote]

一共才2个代码文件...这些格式信息应该是服务自动生成的.没找到方法改

[Quote=引用 4 楼 foolbirdflyfirst 的回复:]
$parameters=array('text'=>'5do8');
$username = $client->sayHello($parameters);
============================================================================================
$parameters一般不这样传,webservice就是跨平台,跨语言的服务,你把一个专属于php的数组类型传到参数中,除非server端也是php写的,否则其它语言根本不识别此类型,w3c对参数类型是有严格规定的。
感觉就是你这个参数类型错了啊。
[/Quote]
网上找到的php连接c#写的WCF的例子都是这样传参数的阿
foolbirdflyfirst 2009-08-19
  • 打赏
  • 举报
回复
$parameters=array('text'=>'5do8');
$username = $client->sayHello($parameters);
============================================================================================
$parameters一般不这样传,webservice就是跨平台,跨语言的服务,你把一个专属于php的数组类型传到参数中,除非server端也是php写的,否则其它语言根本不识别此类型,w3c对参数类型是有严格规定的。
感觉就是你这个参数类型错了啊。
lgzxz999 2009-08-19
  • 打赏
  • 举报
回复
不知道soap+xml是什么
当方法是有的,先全文件夹查找"'text/xml; charset=utf-8'",然后换成'application/soap+xml; charset=utf-8'试试看
lokiice 2009-08-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zhongqixing1104 的回复:]
这么明显的提示都不知道怎么解决?
[/Quote]

怒~
知道是什么错和知道怎么解决时两码事
zhongqixing1104 2009-08-14
  • 打赏
  • 举报
回复
这么明显的提示都不知道怎么解决?

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧