【问题标题】:Problem with WCF BasicHttpBindingWCF BasicHttpBinding 的问题
【发布时间】: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


【解决方案1】:

尝试直接进入服务 (http://xxx.xxx.com/TMServices/PURLServ.svc) 页面。您的服务中可能存在阻止加载的问题,当您尝试浏览它时,您应该了解它是什么。

我的记忆很模糊,但我似乎记得在过去看到过类似的行为(“无法处理消息,因为内容类型 'text/xml; charset=utf-8' 不是预期的类型 'application/soap+ xml; charset=utf-8'.") 当我遇到服务无法加载的问题时。

【讨论】:

    【解决方案2】:

    首先确保您的 WCF 服务和 PHP 客户端在 basicHttpBinding 上使用相同版本的 SOAP 协议 (1.1)。

    通过引用 WSDL 文件来创建您的 PHP 客户端。

    例如:

    // Create a new soap client based on the service's metadata (WSDL)
    $client = new SoapClient("http://localhost:8731/FileUploadService?wsdl")
    

    就字符集错误 (UTF-8) 而言,您可以指示您的 PHP 客户端应该使用哪个字符集:

    $client->soap_defencoding = 'UTF-8';
    

    【讨论】:

      猜你喜欢
      • 2012-06-19
      • 1970-01-01
      • 1970-01-01
      • 2011-01-28
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多