2009-01-19 122 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