我做了一個簡單的Web服務消耗從C#中的PHP SOAP服務
WSDL:
<wsdl:definitions name='mysum' >
<wsdl:types>
<xsd:schema
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.my-uni-project.info/joomla/components/com_jv_vm_soa/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="mysum"
targetNamespace="http://www.my-uni-project.info/joomla/components/com_jv_vm_soa/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<xsd:complexType name="mysumRequest">
<xsd:all>
<xsd:element minOccurs="0" name="n1" type="xsd:int"/>
<xsd:element minOccurs="0" name="n2" type="xsd:int"/>
</xsd:all>
</xsd:complexType>
<xsd:element name="mysumResponse" type="xsd:int"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="mysumRequest">
<wsdl:part name="parameters" element="tns:mysumRequest" />
</wsdl:message>
<wsdl:message name="mysumResponse">
<wsdl:part name="result" element="tns:mysumResponse" />
</wsdl:message>
<wsdl:portType name="mysum">
<wsdl:operation name="mysum">
<wsdl:input message="tns:mysumRequest"/>
<wsdl:output message="tns:mysumResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="mysumSOAP" type="tns:mysum">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="mysum">
<soap:operation soapAction="mysum" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="mysum">
<wsdl:port name="mysumSOAP" binding="tns:mysumSOAP">
<soap:address location="http://www.my-uni-
project.info/joomla/components/com_jv_vm_soa/mysum.php" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
服務:
function mysum($parameters) {
$result = $parameters->item[0]->value + $parameters->item[1]->value; return $result ; }
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache $server = new SoapServer("mysum.wsdl"); $server->addFunction("mysum"); $server->handle();
,我可以從一個PHP客戶機訪問:
$client = new SoapClient("http://www.my-uni- project.info/joomla/components/com_jv_vm_soa/mysum.wsdl"); $params = array('n1' => '4', 'n2' => '8');
try {
$result = $client->__soapCall('mysum', array('parameters' => $params));
echo $result; } catch (SoapFault $exception) { echo $exception;
}
我試圖所以首先創建一個C#客戶端我創建服務引用「mysum」,則在表格上我添加一個按鈕和一個標籤和添加以下代碼爲按鈕
private void button1_Click(object sender, EventArgs e)
{
mysum s = new mysum();
label1.Text = "" + s.mysum(2, 3);
}
WHE我運行它我得到這個錯誤:
Error 5 The type or namespace name 'mysum' could not be found (are you
missing a using directive or an assembly reference?)
服務是在線
謝謝你在先進 約翰
尋找更多的到它,我發現有一個與WSDL和Visual Studio無法生成代理類的問題...任何人都發現了嗎? – John 2010-10-28 16:43:22
試圖在其上運行Wsdl.exe用,果然我得到:「錯誤:有是XML文檔中的錯誤(1,2) - ‘WSDL’是一個未聲明的命名空間1號線,位置2」。 – 2010-11-01 20:36:40