<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>I@laoer.com &#187; Web Service</title>
	<atom:link href="http://i.laoer.com/tag/web-service/feed" rel="self" type="application/rss+xml" />
	<link>http://i.laoer.com</link>
	<description>技术、生活、感悟 -- Laoer的博客</description>
	<lastBuildDate>Mon, 30 Jan 2012 10:03:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHP SOAP实践</title>
		<link>http://i.laoer.com/php-soap-webservice.html</link>
		<comments>http://i.laoer.com/php-soap-webservice.html#comments</comments>
		<pubDate>Fri, 27 Mar 2009 07:00:56 +0000</pubDate>
		<dc:creator>Laoer</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[Web Service]]></category>

		<guid isPermaLink="false">http://i.laoer.com/?p=215</guid>
		<description><![CDATA[我现在公司里的系统都是SOA/面向服务架构的，用Java编写的Web Service，理论上Web Service支持异构语言的，我想测试一下用PHP来调用Java的Web Service是否方便。 首先用Java建立一个Web Service服务端（用CXF，JAX-WS实现），下面是公布出来的WSDL 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 &#60;?xml version='1.0' encoding='UTF-8'?&#62;&#60;wsdl:definitions name=&#34;SampleWebService&#34; targetNamespace=&#34;http://www.abc.net/WS/2008&#34; xmlns:ns1=&#34;http://webservice.passport.abc.net/&#34; xmlns:soap=&#34;http://schemas.xmlsoap.org/wsdl/soap/&#34; xmlns:tns=&#34;http://www.abc.net/WS/2008&#34; xmlns:wsdl=&#34;http://schemas.xmlsoap.org/wsdl/&#34; xmlns:xsd=&#34;http://www.w3.org/2001/XMLSchema&#34;&#62; &#60;wsdl:import location=&#34;http://192.168.19.42:8080/sample/service/SampleWebService?wsdl=SampleWebService.wsdl&#34; namespace=&#34;http://webservice.passport.abc.net/&#34;&#62; &#60;/wsdl:import&#62; &#60;wsdl:message name=&#34;helloUser&#34;&#62; &#60;wsdl:part element=&#34;ns1:helloUser&#34; name=&#34;parameters&#34;&#62; &#60;/wsdl:part&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>我现在公司里的系统都是SOA/面向服务架构的，用Java编写的Web Service，理论上Web Service支持异构语言的，我想测试一下用PHP来调用Java的Web Service是否方便。</p>
<p>首先用Java建立一个Web Service服务端（用<a href="http://cxf.apache.org/" target="_blank">CXF</a>，JAX-WS实现），下面是公布出来的WSDL</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">'1.0'</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">'UTF-8'</span><span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #000000; font-weight: bold;">&lt;wsdl:definitions</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SampleWebService&quot;</span> <span style="color: #000066;">targetNamespace</span>=<span style="color: #ff0000;">&quot;http://www.abc.net/WS/2008&quot;</span> <span style="color: #000066;">xmlns:ns1</span>=<span style="color: #ff0000;">&quot;http://webservice.passport.abc.net/&quot;</span> <span style="color: #000066;">xmlns:soap</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/wsdl/soap/&quot;</span> <span style="color: #000066;">xmlns:tns</span>=<span style="color: #ff0000;">&quot;http://www.abc.net/WS/2008&quot;</span> <span style="color: #000066;">xmlns:wsdl</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/wsdl/&quot;</span> <span style="color: #000066;">xmlns:xsd</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:import</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;http://192.168.19.42:8080/sample/service/SampleWebService?wsdl=SampleWebService.wsdl&quot;</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;http://webservice.passport.abc.net/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:import<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:message</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;helloUser&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:part</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">&quot;ns1:helloUser&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;parameters&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:part<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:message</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;helloUserResponse&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:part</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">&quot;ns1:helloUserResponse&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;parameters&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:part<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:binding</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SampleWebServiceSoapBinding&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;ns1:SampleWebService&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:binding</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;document&quot;</span> <span style="color: #000066;">transport</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/soap/http&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;helloUser&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:operation</span> <span style="color: #000066;">soapAction</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;document&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:input</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;helloUser&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:body</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">&quot;literal&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:input<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:output</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;helloUserResponse&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:body</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">&quot;literal&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:output<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:operation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:binding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:service</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SampleWebService&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:port</span> <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;tns:SampleWebServiceSoapBinding&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SampleWebServicePort&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:address</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;http://192.168.19.42:8080/sample/service/SampleWebService&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:port<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:definitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>这个Web Service有个“helloUser”方法，传入一个参数，它返回一段文本“Hello 参数!”，</p>
<p>PHP5之后已经加入了SOAP的支持，我最开始用PHP5的SOAP函数来调用，下面是代码</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SoapClient<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://192.168.19.42:8080/sample/service/SampleWebService?wsdl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span>__getFunctions<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>但报错Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: &lt;message&gt; &#8216;helloUser&#8217; already defined in &#8230;，我搜了PHP网站上的相关文档也没找到答案，没办法，我只能找其他SOAP的组件，找到了<a href="http://sourceforge.net/projects/nusoap/" target="_blank">NuSOAP</a>，它最近发布的版本是0.7.3，是在2007年发布的，现在已经2009了，用用试试吧，参考nusoap的例子，写好自己代码</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'nusoap.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> nusoap_client<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://192.168.19.42:8080/sample/service/SampleWebService?wsdl'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wsdl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$err</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getError</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$err</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;h2&gt;Constructor error&lt;/h2&gt;&lt;p&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$err</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$param</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'arg0'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'laoer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">call</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'helloUser'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'parameters'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;http://webservice.passport.abc.net/&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;document&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;literal&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fault</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;h2&gt;Fault&lt;/h2&gt;&lt;p&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Check for errors</span>
	<span style="color: #000088;">$err</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getError</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$err</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Display the error</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;h2&gt;Error&lt;/h2&gt;&lt;p&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$err</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Display the result</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;h2&gt;Result&lt;/h2&gt;&lt;p&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//print_r($result);</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;return&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;h2&gt;Request&lt;/h2&gt;&lt;p&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">ENT_QUOTES</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;h2&gt;Response&lt;/h2&gt;&lt;p&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">response</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">ENT_QUOTES</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>执行结果</p>
<p>Result<br />
Hello laoer!</p>
<p>Request<br />
POST /sample/service/SampleWebService HTTP/1.0<br />
Host: 192.168.19.42:8080<br />
User-Agent: NuSOAP/0.7.3 (1.114)<br />
Content-Type: text/xml; charset=UTF-8<br />
SOAPAction: “”<br />
Content-Length: 436</p>
<p>我们可以看到Request的SOAP文本</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SOAP-ENV:Envelope</span> <span style="color: #000066;">xmlns:SOAP-ENV</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;</span> <span style="color: #000066;">xmlns:xsd</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema&quot;</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> <span style="color: #000066;">xmlns:SOAP-ENC</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/soap/encoding/&quot;</span> <span style="color: #000066;">xmlns:ns1</span>=<span style="color: #ff0000;">&quot;http://webservice.passport.abc.net/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SOAP-ENV:Body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;helloUser</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg0</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>laoer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/arg0<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/helloUser<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SOAP-ENV:Body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SOAP-ENV:Envelope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Response<br />
HTTP/1.1 200 OK<br />
Server: Apache-Coyote/1.1<br />
SOAPAction: “”<br />
Content-Type: text/xml;charset=UTF-8<br />
Content-Length: 237<br />
Date: Fri, 27 Mar 2009 04:27:11 GMT<br />
Connection: close</p>
<p>Response的SOAP文本</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:Envelope</span> <span style="color: #000066;">xmlns:soap</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:Body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ns2:helloUserResponse</span> <span style="color: #000066;">xmlns:ns2</span>=<span style="color: #ff0000;">&quot;http://webservice.passport.abc.net/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;return<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Hello laoer!<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/return<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ns2:helloUserResponse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/soap:Body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/soap:Envelope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>碰到一个小问题就是PHP给方法传参数，看是我不知道怎么填，后来我用soapUI，做了一个SOAP Request的例子，发现参数的Name是arg0，如果是多个参数，则arg0、arg1、arg2&#8230;以此类推，所以我们定义的参数是$param = array(&#8216;arg0&#8242;=>&#8217;laoer&#8217;)，还有就是nusoap里对返回信息的编码有点问题，如果你Web Service放回的编码是UTF-8，则nusoap多转换了一次，在nusoap.php文件nusoap_client类里把$decode_utf8置为false就可以了。</p>
]]></content:encoded>
			<wfw:commentRss>http://i.laoer.com/php-soap-webservice.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

