c# - 使用具有父子关系 VB 或 C# 的 Web 服务

标签 c# xml vb.net wsdl

我希望我在这里遗漏了一些非常简单的东西。

我需要使用特定患者正在使用的药物列表来更新 Web 服务。我正在发送患者的 ID 以及药物 list 。我已获得以下 WSDL

<?xml version="1.0" encoding="UTF-8"?>

-<wsdl:definitions name="GOLDSessionResponseService" 
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" 
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" 
xmlns:wsa10="http://www.w3.org/2005/08/addressing" 
xmlns:tns="http://City.health.xxx.au/" 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" 
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" 
xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" 
xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" 
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
targetNamespace="http://City.health.xxx.au/">

-<wsdl:types>

-<xs:schema targetNamespace="http://City.health.xxx.au/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

  <xs:import namespace="http://schemas.datacontract.org/2004/07/City.Services.GOLD"/>


  -<xs:element name="SessionCompleted">


    -<xs:complexType>


      -<xs:sequence>

        <xs:element type="q1:SessionCompletionRequest" name="request" xmlns:q1="http://schemas.datacontract.org/2004/07/City.Services.GOLD" nillable="true" minOccurs="0"/>

      </xs:sequence>

    </xs:complexType>

  </xs:element>


  -<xs:element name="SessionCompletedResponse">


    -<xs:complexType>


      -<xs:sequence>

        <xs:element type="q2:SessionCompletionResponse" name="SessionCompletedResult" nillable="true" minOccurs="0" xmlns:q2="http://schemas.datacontract.org/2004/07/City.Services.GOLD"/>

      </xs:sequence>

    </xs:complexType>

  </xs:element>


  -<xs:element name="UpdateMedications">


    -<xs:complexType>


      -<xs:sequence>

        <xs:element type="q3:UpdateMedicationsRequest" name="request" nillable="true" minOccurs="0" xmlns:q3="http://schemas.datacontract.org/2004/07/City.Services.GOLD"/>

      </xs:sequence>

    </xs:complexType>

  </xs:element>


  -<xs:element name="UpdateMedicationsResponse">


    -<xs:complexType>


      -<xs:sequence>

        <xs:element type="q4:UpdateMedicationsResponse" name="UpdateMedicationsResult" nillable="true" minOccurs="0" xmlns:q4="http://schemas.datacontract.org/2004/07/City.Services.GOLD"/>

      </xs:sequence>

    </xs:complexType>

  </xs:element>

</xs:schema>


-<xs:schema xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="qualified">

  <xs:element type="xs:anyType" name="anyType" nillable="true"/>

  <xs:element type="xs:anyURI" name="anyURI" nillable="true"/>

  <xs:element type="xs:base64Binary" name="base64Binary" nillable="true"/>

  <xs:element type="xs:boolean" name="boolean" nillable="true"/>

  <xs:element type="xs:byte" name="byte" nillable="true"/>

  <xs:element type="xs:dateTime" name="dateTime" nillable="true"/>

  <xs:element type="xs:decimal" name="decimal" nillable="true"/>

  <xs:element type="xs:double" name="double" nillable="true"/>

  <xs:element type="xs:float" name="float" nillable="true"/>

  <xs:element type="xs:int" name="int" nillable="true"/>

  <xs:element type="xs:long" name="long" nillable="true"/>

  <xs:element type="xs:QName" name="QName" nillable="true"/>

  <xs:element type="xs:short" name="short" nillable="true"/>

  <xs:element type="xs:string" name="string" nillable="true"/>

  <xs:element type="xs:unsignedByte" name="unsignedByte" nillable="true"/>

  <xs:element type="xs:unsignedInt" name="unsignedInt" nillable="true"/>

  <xs:element type="xs:unsignedLong" name="unsignedLong" nillable="true"/>

  <xs:element type="xs:unsignedShort" name="unsignedShort" nillable="true"/>

  <xs:element type="tns:char" name="char" nillable="true"/>


  -<xs:simpleType name="char">

    <xs:restriction base="xs:int"/>

  </xs:simpleType>

  <xs:element type="tns:duration" name="duration" nillable="true"/>


  -<xs:simpleType name="duration">


    -<xs:restriction base="xs:duration">

      <xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?"/>

      <xs:minInclusive value="-P10675199DT2H48M5.4775808S"/>

      <xs:maxInclusive value="P10675199DT2H48M5.4775807S"/>

    </xs:restriction>

  </xs:simpleType>

  <xs:element type="tns:guid" name="guid" nillable="true"/>


  -<xs:simpleType name="guid">


    -<xs:restriction base="xs:string">

      <xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}"/>

    </xs:restriction>

  </xs:simpleType>

  <xs:attribute type="xs:QName" name="FactoryType"/>

  <xs:attribute type="xs:ID" name="Id"/>

  <xs:attribute type="xs:IDREF" name="Ref"/>

</xs:schema>


-<xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/City.Services.GOLD" targetNamespace="http://schemas.datacontract.org/2004/07/City.Services.GOLD" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">


  -<xs:complexType name="SessionCompletionRequest">


    -<xs:sequence>

      <xs:element type="xs:dateTime" name="AppointmentDateTime" minOccurs="0"/>

      <xs:element type="xs:dateTime" name="NextAppointmentDateTime" minOccurs="0"/>

      <xs:element type="xs:int" name="PatientId" minOccurs="0"/>

      <xs:element type="xs:string" name="SessionLetter" nillable="true" minOccurs="0"/>

      <xs:element type="xs:int" name="SessionNumber" minOccurs="0"/>

      <xs:element type="xs:string" name="Status" nillable="true" minOccurs="0"/>

    </xs:sequence>

  </xs:complexType>

  <xs:element type="tns:SessionCompletionRequest" name="SessionCompletionRequest" nillable="true"/>


  -<xs:complexType name="SessionCompletionResponse">


    -<xs:sequence>

      <xs:element type="xs:string" name="ErrorMessage" nillable="true" minOccurs="0"/>

      <xs:element type="xs:boolean" name="Success" minOccurs="0"/>

    </xs:sequence>

  </xs:complexType>

  <xs:element type="tns:SessionCompletionResponse" name="SessionCompletionResponse" nillable="true"/>


  -<xs:complexType name="UpdateMedicationsRequest">


    -<xs:sequence>

      <xs:element type="tns:Medication" name="Medications" nillable="true" minOccurs="0"/>

      <xs:element type="xs:int" name="PatientId" minOccurs="0"/>

    </xs:sequence>

  </xs:complexType>

  <xs:element type="tns:UpdateMedicationsRequest" name="UpdateMedicationsRequest" nillable="true"/>


  -<xs:complexType name="Medication">


    -<xs:sequence>

      <xs:element type="xs:string" name="BrandName" nillable="true" minOccurs="0"/>

      <xs:element type="xs:string" name="Generic" nillable="true" minOccurs="0"/>

    </xs:sequence>

  </xs:complexType>

  <xs:element type="tns:Medication" name="Medication" nillable="true"/>


  -<xs:complexType name="UpdateMedicationsResponse">


    -<xs:sequence>

      <xs:element type="xs:string" name="ErrorMessage" nillable="true" minOccurs="0"/>

      <xs:element type="xs:boolean" name="Success" minOccurs="0"/>

    </xs:sequence>

  </xs:complexType>

  <xs:element type="tns:UpdateMedicationsResponse" name="UpdateMedicationsResponse" nillable="true"/>

</xs:schema>

-<wsdl:message name="IGOLDSessionResponseService_SessionCompleted_InputMessage">

    <wsdl:part name="parameters" element="tns:SessionCompleted"/>

</wsdl:message>


-<wsdl:message name="IGOLDSessionResponseService_SessionCompleted_OutputMessage">

    <wsdl:part name="parameters" element="tns:SessionCompletedResponse"/>

</wsdl:message>


-<wsdl:message name="IGOLDSessionResponseService_UpdateMedications_InputMessage">

    <wsdl:part name="parameters" element="tns:UpdateMedications"/>

</wsdl:message>


-<wsdl:message name="IGOLDSessionResponseService_UpdateMedications_OutputMessage">

    <wsdl:part name="parameters" element="tns:UpdateMedicationsResponse"/>

</wsdl:message>


-<wsdl:portType name="IGOLDSessionResponseService">


-<wsdl:operation name="SessionCompleted">

  <wsdl:input message="tns:IGOLDSessionResponseService_SessionCompleted_InputMessage" wsaw:Action="http://City.health.xxx.au/IGOLDSessionResponseService/SessionCompleted"/>

  <wsdl:output message="tns:IGOLDSessionResponseService_SessionCompleted_OutputMessage" wsaw:Action="http://City.health.xxx.au/IGOLDSessionResponseService/SessionCompletedResponse"/>

</wsdl:operation>


-<wsdl:operation name="UpdateMedications">

  <wsdl:input message="tns:IGOLDSessionResponseService_UpdateMedications_InputMessage" wsaw:Action="http://City.health.xxx.au/IGOLDSessionResponseService/UpdateMedications"/>

  <wsdl:output message="tns:IGOLDSessionResponseService_UpdateMedications_OutputMessage" wsaw:Action="http://City.health.xxx.au/IGOLDSessionResponseService/UpdateMedicationsResponse"/>

</wsdl:operation>

-<wsdl:binding type="tns:IGOLDSessionResponseService" name="BasicHttpBinding_IGOLDSessionResponseService">

<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>


-<wsdl:operation name="SessionCompleted">

  <soap:operation style="document" soapAction="http://City.health.xxx.au/IGOLDSessionResponseService/SessionCompleted"/>


  -<wsdl:input>

    <soap:body use="literal"/>

  </wsdl:input>


  -<wsdl:output>

    <soap:body use="literal"/>

  </wsdl:output>

</wsdl:operation>


-<wsdl:operation name="UpdateMedications">

  <soap:operation style="document" soapAction="http://City.health.xxx.au/IGOLDSessionResponseService/UpdateMedications"/>


  -<wsdl:input>

    <soap:body use="literal"/>

  </wsdl:input>


  -<wsdl:output>

    <soap:body use="literal"/>

  </wsdl:output>

</wsdl:operation>

</wsdl:binding>


-<wsdl:service name="GOLDSessionResponseService">


-<wsdl:port name="BasicHttpBinding_IGOLDSessionResponseService" binding="tns:BasicHttpBinding_IGOLDSessionResponseService">

  <soap:address location="http://services.City.simient.com/GOLD/GOLDSessionResponseService.svc"/>

</wsdl:port>

我已将 WebReference 添加到我的项目并尝试使用这些服务。我在尝试将药物链接到患者 ID 时遇到错误。

代码如下:

Dim medadd As Services.UpdateMedicationsRequest = New Services.UpdateMedicationsRequest()
Dim medresponse As Services.UpdateMedicationsResponse = New Services.UpdateMedicationsResponse()

Dim medlist As Medication = New Medication()


medadd.PatientId = CInt(patientid)
medadd.PatientIdSpecified = True
medlist.BrandName = "testbrand"
medlist.Generic = "testgeneric"


medadd.Medications = medlist??????


medresponse = client.UpdateMedications(medadd)

我在尝试将药物添加到父类时卡住了。

如有任何建议,我们将不胜感激

最佳答案

medadd.Medications 是 Medication 元素的集合,因此您必须使用特定的添加方法,而不仅仅是将 medication 元素分配给 medications

应该是这样的

medadd.Medications.Add(medlist);

如果尚未分配药物(无),则必须在执行添加操作之前创建一个新的空药物列表

Dim medications As New List(Of Medication)();
medications.Add(medlist);
medadd.Medications = medications;

另一个可能产生问题的是药物的 minOccurs = 0。应该是 minOccurs = 1

关于c# - 使用具有父子关系 VB 或 C# 的 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40759436/

相关文章:

c# - 仅获取实现接口(interface)的属性

c# - MVC 传递模型与 View 模型 - 如何保留模型元信息?

c# - A* 寻路在 3D Minecraft 环境中不起作用

c# - 使用数据流调用起订量验证方法

c# - 智能 HTML 编码

java - 使用 Android 应用程序调用 Textview 值

VB.NET:SelectedIndexChanged 多次触发

Android XML 在另一个布局上插入一个布局

windows - 如果应用程序未运行,如何删除文件?

vb.net - 为什么我在通过 "no data is present"测试后收到 "HasRows"错误?