doupang5433
2015-02-28 16:37
浏览 189

SoapClient中的Web服务URL和SOAP-ERROR:解析WSDL错误

There is a web service URL which returns a country's cities details. I can access this web service URL in browser by direct Http Request using GET method and works fine :

[Snip: I changed my actual domain name with example]

http://alpha.example.com/WSV2/StaticData.php?xml=<StaticDataRequest><Header><Code>TT4533</Code><Username>skyman211</Username><Password>ammkj43</Password></Header><Body><GetStaticData>cities</GetStaticData><ExtraParams><CountryCode>67</CountryCode></ExtraParams></Body></StaticDataRequest>

But when I try to access above URL via SoapClient :

/* Line 36 */
$cities = new SoapClient("http://alpha.example.com/WSV2/StaticData.php?xml=<StaticDataRequest><Header><Code>TT4533</Code><Username>skyman211</Username><Password>ammkj43</Password></Header><Body><GetStaticData>cities</GetStaticData><ExtraParams><CountryCode>67</CountryCode></ExtraParams></Body></StaticDataRequest>");

Gets me following error :

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL:
Couldn't find <definitions> in 'http://alpha.example.com/WSV2/StaticData.php?xml=
<StaticDataRequest><Header><Code>TT4533</Code><Username>skyman211</Username>
<Password>ammkj43</Password></Header><Body><GetStaticData>cities</GetStaticData>
<ExtraParams><CountryCode>67</CountryCode></ExtraParams></Body></StaticDataRequest>'
in /srv/www/htdocs/test/inc/client.php:36 Stack trace: #0 /srv/www/htdocs/test/
inc/client.php(36): SoapClient->SoapClient('http://alpha.ex...') #1 /srv/www/
htdocs/ortmas/index.php(6): InitData->getCities(67) #2 {main} thrown in /srv/
www/htdocs/test/inc/client.php on line 36

图片转代码服务由CSDN问答提供 功能建议

有一个Web服务URL可以返回国家/地区的城市详细信息。 我可以使用GET方法通过直接Http请求在浏览器中访问此Web服务URL 并正常工作:

[Snip:我用示例更改了我的实际域名 ]

 <代码> http://alpha.example.com/WSV2/StaticData.php?xml=<StaticDataRequest><Header><  ;代码&GT; TT4533&LT; /代码&GT;&lt;用户名&GT; skyman211&LT; /用户名&gt;&LT;密码&GT; ammkj43&LT; /密码和GT;&LT; /页眉和GT;&LT;身体与GT;&LT; GetStaticData&GT;城市&LT; / GetStaticData&GT;&LT; ExtraParams&GT;&LT;  CountryCode&gt; 67&lt; / CountryCode&gt;&lt; / ExtraParams&gt;&lt; / Body&gt;&lt; / StaticDataRequest&gt; 
   
 
 

但是当我尝试通过SoapClient访问上述网址时:

  / *第36行* / 
 $ cities = new SoapClient(“http://alpha.example.com/WSV2/StaticData.php?xml=<StaticDataRequest>  ;&LT;页眉和GT;&LT;代码&GT; TT4533&LT; /代码&GT;&lt;用户名&GT; skyman211&LT; /用户名&gt;&LT;密码&GT; ammkj43&LT; /密码和GT;&LT; /页眉和GT;&LT;身体与GT;&LT; GetStaticData&GT;城市&LT; /获取 taticData&GT;&LT; ExtraParams&GT;&LT; COUNTRYCODE&GT; 67&LT; / COUNTRYCODE&GT;&LT; / ExtraParams&GT;&LT; /身体&GT;&LT; / StaticDataRequest&gt;“中); 
   
 
 

得到以下错误:

 致命错误:未捕获的SoapFault异常:[WSDL] SOAP-ERROR:解析WSDL:
无法找到&lt; definitions&gt; 在'http://alpha.example.com/WSV2/StaticData.php?xml=
<StaticDataRequest><Header><Code>TT4533</Code><Username>skyman211</Username>
< 密码&GT; ammkj43&LT; /密码&GT;&LT; /页眉和GT;&LT;身体与GT;&LT; GetStaticData&GT;城市&LT; / GetStaticData&GT; 
&LT; ExtraParams&GT;&LT; COUNTRYCODE&GT; 67&LT; / COUNTRYCODE&GT;&LT; / ExtraParams&GT;&LT; /身体&GT;&LT  ; / StaticDataRequest&gt;'
in /srv/www/htdocs/test/inc/client.php:36堆栈跟踪:#0 /srv/www/htdocs/test/
inc/client.php(36):SoapClient-&gt  ; SoapClient('http://alpha.ex ...')#1 /srv/www/
htdocs/ortmas/index.php(6):InitData-&gt; getCities(67)#2 {main}引入 第36行上的/srv/
www/htdocs/test/inc/client.php 
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanhe2027 2015-02-28 16:42
    已采纳

    You must pass the URL to the WSDL, instead of the actual call itself.

    Something like that for example :

    $cities = new SoapClient("http://alpha.example.com/WSV2/StaticData.wsdl");

    If that url worked on your browser, you can try to do the following in PHP :

    $url = "http://alpha.example.com/WSV2/StaticData.php?xml=<StaticDataRequest><Header><Code>TT4533</Code><Username>skyman211</Username><Password>ammkj43</Password></Header><Body><GetStaticData>cities</GetStaticData><ExtraParams><CountryCode>67</CountryCode></ExtraParams></Body></StaticDataRequest>";  
    
    $data = file_get_contents($url);
    
    已采纳该答案
    打赏 评论