2009-01-19 126 views

回答

4

创建一个与WSDL匹配并通过HTTP POST发送的SOAP XML文档。 见here for an example

您发送此:

POST /webservices/tempconvert.asmx HTTP/1.1 
Host: www.w3schools.com 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <CelsiusToFahrenheit xmlns="http://tempuri.org/"> 
     <Celsius>string</Celsius> 
    </CelsiusToFahrenheit> 
    </soap12:Body> 
</soap12:Envelope> 

而且把它恢复:

HTTP/1.1 200 OK 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <CelsiusToFahrenheitResponse xmlns="http://tempuri.org/"> 
     <CelsiusToFahrenheitResult>string</CelsiusToFahrenheitResult> 
    </CelsiusToFahrenheitResponse> 
    </soap12:Body> 
</soap12:Envelope> 
+0

嗨Josh, 如果我希望从web服务获取报告文件(以PDF格式为文件)到php,那么仍然是使用最好的方法? – 2009-01-21 01:13:58

+0

@Jin:您可以通过使用UUEncode或base64对返回的XML进行编码来直接发送二进制文件。一个更好的计划是在服务器上生成PDF,给它一个唯一的URL,然后客户端可以在两个请求中获取报告 - 一个SOAP请求生成报告,然后是一个普通的http请求来检索报告。 – Eclipse 2010-01-28 16:37:04

0

我从来没有在PHP的> C#做这件事,我用C#调用PHP Web服务和我对于本地PHP类,我总是使用Zend Framework包装器。您应该查看Zend_Soap_Client,如果它与Zend_Soap_Server类似,则只是在PHP SOAP类中包含一些增值内容的包装。

而且,我应该说,它所做的一切就是将@Josh说成一个很好的课程,并自动为你做一些事情。

1

没有什么东西叫做“C#Web服务”。你的意思是基于SOAP远程调用和WSDL描述的XML Web服务。

事实上,所有的SOAP服务都应该是兼容的,无论是.Net,PHP还是Java。但在实践中,小问题会让问题变得更加困难。

PHP有许多不同的SOAP库,但用于连接PHP的ASP.NET XML Web Service,但nuSOAP为我提供了最好的结果。它基本上是一组使用基于SOAP的Web服务的PHP类。最简单的客户端代码看起来是这样的:

<?php 
// Pull in the NuSOAP code 
require_once('nusoap.php'); 
// Create the client instance 
$client = new soapclient('http://localhost/phphack/helloworld.php'); 
// Call the SOAP method 
$result = $client->call('hello', array('name' => 'Scott')); 
// Display the result 
print_r($result); 
?> 

更多的例子见http://www.scottnichol.com/nusoapintro.htm