繁体   English   中英

消耗来自C#的php soap服务

[英]consume a php soap service from C#

我做了一个简单的网络服务

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();

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();

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”,然后在表单上添加了一个按钮和一个标签,并为该按钮添加了以下代码

Error 5 The type or namespace name 'mysum' could not be found (are you 
missing a using directive or an assembly reference?) 

我运行它时收到此错误:

 Error 5 The type or namespace name 'mysum' could not be found (are you missing a using directive or an assembly reference?) 

该服务在线

谢谢高级约翰

我认为您的问题是您将服务添加为服务参考,而不是Web服务参考。

添加Web服务参考

  1. 添加服务参考
  2. 点击窗口上的高级按钮
  3. 点击添加网站参考
  4. 输入服务网址

也,

确保在项目中添加了System.Web.Services命名空间引用。

希望能帮助到你。

通常,您可以通过右键单击有问题的对象(在本例中为mysum),然后查看是否可以使用指令来确定是否可以使用指令解决问题。 '在哪里 是指令的名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM