【问题标题】:c# web service consumption errorc# web服务消费报错
【发布时间】:2012-07-09 15:30:58
【问题描述】:

我正在尝试使用来自 .NET C# 项目的以下 WSDL 来使用 Web 服务。

我添加了网络参考等并尝试调用方法(getPatients),但它总是返回错误:

"MyService.PatientType[] PatientService.getPatients(MyService.getPatients getPatients1)"
"No overload for method 'getPatients' takes 0 arguments"

我认为我的代码没问题(和我之前成功使用过的一样)但我一定是做错了什么......

MyService.PatientService ws = new MyService.PatientService();
string message = ws.getPatients();

有人有什么想法吗?

谢谢

WSDL:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions name="patient"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:tns="http://www.example.org/patientservice/" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:p1="http://www.example.org/patientservice/patient_types/"
targetNamespace="http://www.example.org/patientservice/">
<wsdl:types>
<xsd:schema targetNamespace="http://www.example.org/patientservice/patient_types/" 
xmlns:tns="http://www.example.org/patientservice/patient_types/"    
xmlns:ns1="http://www.example.org/patient"
elementFormDefault="qualified">

<xsd:complexType name="patientType">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="age" type="xsd:int"/>
<xsd:element name="ssn" type="xsd:string"/>
<xsd:element name="pid" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>

<xsd:element name="getPatients">
<xsd:complexType/>
</xsd:element>

<xsd:element name="getPatientsResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="patient" type="tns:patientType" maxOccurs="unbounded" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="getPatient">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ssn" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="getPatientResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="patient" type="tns:patientType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

</xsd:schema>
</wsdl:types>
<wsdl:message name="getPatientsRequest">
<wsdl:part element="p1:getPatients" name="in"/>
</wsdl:message>
<wsdl:message name="getPatientsResponse">
<wsdl:part element="p1:getPatientsResponse" name="out"/>
</wsdl:message>
<wsdl:message name="getPatientRequest">
<wsdl:part name="in" element="p1:getPatient"></wsdl:part>
</wsdl:message>
<wsdl:message name="getPatientResponse">
<wsdl:part name="out" element="p1:getPatientResponse"></wsdl:part>
</wsdl:message>
<wsdl:portType name="patient">
<wsdl:operation name="getPatients">
<wsdl:input message="tns:getPatientsRequest"/>
<wsdl:output message="tns:getPatientsResponse"/>
</wsdl:operation>
<wsdl:operation name="getPatient">
<wsdl:input message="tns:getPatientRequest"></wsdl:input>
<wsdl:output message="tns:getPatientResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="patientSOAP" type="tns:patient">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getPatients">
<soap:operation  style="document" soapAction=""/>
<wsdl:input name="getPatientsRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getPatientsResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getPatient">
<soap:operation  style="document" soapAction=""/>
<wsdl:input name="getPatientRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getPatientResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="PatientService">
<wsdl:port binding="tns:patientSOAP" name="PatientSOAPPort">
<soap:address location="http://192.168.100.1:8080/patientservice"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

【问题讨论】:

    标签: c# web-services wsdl consumer


    【解决方案1】:

    我已经针对 wsdl 生成了一个代理,似乎 getPatients 方法需要一个参数。

    试试这个:

    PatientService ws = new PatientService();
    getPatients getPatients1 = new getPatients();
    patientType[] patients = ws.getPatients(getPatients1);
    

    【讨论】:

    • 嗨,alex,这行得通,但它不会转换为字符串。我也尝试过使用患者类型,但没有奏效。我确定我也尝试过你的建议:)
    • 您可以随时尝试使用 var response = ws.getPatients(getPatient1) 并调试以查看它返回的类型。
    • Troy 说的会起作用,但是如果你想使用返回的实际类型,我已经用正确的返回类型修改了代码,它是一个患者类型的数组。
    • 工作得很好,谢谢。还试图让第二种方法返回一条记录,这也很有效。再次感谢。
    猜你喜欢
    • 2016-03-17
    • 1970-01-01
    • 2014-12-01
    • 2013-09-22
    • 2013-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-05
    相关资源
    最近更新 更多