【发布时间】:2011-07-12 15:24:33
【问题描述】:
我创建了一个 WCF 服务,我有两个端点,一个用于 wsHttpBinding,一个用于 basicHttpBinding。 我可以使用 wsHttpBinding 和 basicHttpBinding,使用 ASP.Net 调用就可以了。
我在尝试使用 php 使用 basicHttpBinding 服务时遇到问题。
这是元数据。
<wsdl:definitions name="PURLService" targetNamespace="http://xxx.xxx.com/TMServices/">
<wsdl:import namespace="http://tempuri.org/" location="http://xxx.xxx.com/TMServices/PURLServ.svc?wsdl=wsdl1"/>
<wsdl:types/>
<wsdl:service name="PURLService">
<wsdl:port name="WSHttpBinding_ITMService" binding="i0:WSHttpBinding_ITMService">
<soap12:address location="http://xxx.xxx.com/TMServices/PURLServ.svc/ws"/>
<wsa10:EndpointReference>
<wsa10:Address>http://xxx.xxx.com/TMServices/PURLServ.svc/ws</wsa10:Address>
<Identity>
<Spn>host/xxx.xxx.com</Spn>
</Identity>
</wsa10:EndpointReference>
</wsdl:port>
<wsdl:port name="BasicHttpBinding_ITMService" binding="i0:BasicHttpBinding_ITMService">
<soap:address location="http://xxx.xxx.com/TMServices/PURLServ.svc/basic"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
当我尝试通过在 php 上提供地址 http://xxx.xxx.com/TMServices/PURLServ.svc/basic 来调用 basicHttpBinding 端点时,我收到以下错误“SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://xxx.xxx.com/TMServices /PURLServ.svc/basic' : 加载外部实体失败"
这是 php 代码:
$wsdl = "http://xxx.xxx.com/TMServices/PURLServ.svc/basic";
try {
$client = new SoapClient($wsdl);
$result = $client->TestServices(); //this should return true if accessed
print $result;
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>
我也无法直接访问http://xxx.xxx.com/TMServices/PURLServ.svc/basic,我收到 400 Bad Request 错误。
当我尝试在 php 代码上使用 http://xxx.xxx.com/TMServices/PURLServ.svc?wsdl 地址时,我收到以下错误:“无法处理消息,因为内容类型 'text/xml; charset=utf-8' 不是预期的类型 'application/soap +xml; charset=utf-8'."
感谢您的帮助。
【问题讨论】:
-
可以直接访问xxx.xxx.com/TMServices/PURLServ.svc吗? (不添加 /basic)
-
@Tim 是的,我可以。它显示了默认页面,并为我提供了指向 xxx.xxx.com/TMServices/PURLServ.svc?wsdl 的链接,该链接也可以使用
-
对于 .. 'text/xml; charset=utf-8' 不是预期的类型 'application/soap+xml; charset=utf-8' 错误。您必须在 SoapClient 中定义 SOAP_1_2。这会将标题中的 'text/xml' 更改为 'application/soap+xml' => $client = new SoapClient($wsdl, array('soap_version' => SOAP_1_2));
标签: php .net wcf web-services