1

我正在尝试编写一些 C# 代码来调用 Web 服务。我正在尝试对用户进行身份验证(authenticateToNCIDv2Request),然后查看结果(authenticateToNCIDv2Result)。我不明白,基于wsdl,如何做到这一点。

我的代码(这是错误的)看起来像:

SingleSignOn.authenticateToNCIDv2Request request = new SingleSignOn.authenticateToNCIDv2Request();
request.AppID = "1234";
request.AppPassword = "appPW";
request.UserID = "testUser";
request.UserPassword = "userPW";

request = new authenticateToNCIDv2Request1(request).authenticateToNCIDv2Request;

SingleSignOnTest.SingleSignOn.authenticateToNCIDv2Response resp = new SingleSignOn.authenticateToNCIDv2Response();
SingleSignOn.authenticateToNCIDv2Result rslt = resp.authenticateToNCIDv2Result;


string y = rslt.Error;
SingleSignOn.Message[] msg = rslt.MessageArray;

wsdl(为了简洁去掉了不适用的部分)如下:


<xs:element name="authenticateToNCIDv2Response" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:sequence xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element ref="ncidng:authenticateToNCIDv2Result" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
    </xs:sequence>
    </xs:complexType>
</xs:element>
 <xs:element name="authenticateToNCIDv2Result" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:sequence xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element maxOccurs="1" minOccurs="0" ref="ncidng:MessageArray" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
        <xs:element maxOccurs="1" minOccurs="0" name="Error" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
    </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:element name="MessageArray" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:sequence xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xs:element maxOccurs="unbounded" ref="ncidng:Message" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
        </xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Message" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
 <xs:complexType mixed="true" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:attribute name="code" type="xs:NMTOKEN" use="required" xmlns:xs="http://www.w3.org/2001/XMLSchema"/> 
  </xs:complexType> 
</xs:element>


<xs:group name="userinfogroup" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:sequence xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xs:element maxOccurs="1" minOccurs="1" name="User_DN" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="1" name="User_ID" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="0" name="Personal_Title" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="1" name="First_Name" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="0" name="Middle_Initial" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="1" name="Last_Name" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="1" name="Full_Name" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="0" name="Suffix" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="1" name="User_Type" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="0" name="Employee_Type" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="1" name="GUID" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="0" name="Account_Expiration_Date" type="xs:dateTime" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="0" name="Login_Disabled" type="xs:boolean" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="0" name="Locked_by_Intruder" type="xs:boolean" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="0" name="Password_Expiration_Date" type="xs:dateTime" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="0" name="Second_Factor_Role" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="1" name="Account_Status" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="0" name="Migration_Status" type="xs:boolean" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
        <xs:element maxOccurs="1" minOccurs="0" name="Business_Phone" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
        <xs:element maxOccurs="1" minOccurs="0" name="Business_Phone_Ext" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
      <xs:element maxOccurs="1" minOccurs="1" name="eMail" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>           
          <xs:element maxOccurs="1" minOccurs="0" name="Street" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
          <xs:element maxOccurs="1" minOccurs="0" name="Address_Line2" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
          <xs:element maxOccurs="1" minOccurs="0" name="City" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
          <xs:element maxOccurs="1" minOccurs="0" name="State" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
          <xs:element maxOccurs="1" minOccurs="0" name="Zip_Code" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
          <xs:element maxOccurs="1" minOccurs="0" name="CR_Config" type="xs:boolean" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>         
            <xs:element maxOccurs="1" minOccurs="0" ref="ncidng:Member_of_OrganizationArray" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="0" ref="ncidng:Member_of_DivisionArray" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            <xs:element maxOccurs="1" minOccurs="0" ref="ncidng:Member_of_SectionArray" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>                               
        </xs:sequence>          
</xs:group>

<xs:element name="NCIDWebServiceException" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:sequence xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xs:element name="reason" nillable="true" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
        </xs:sequence>
    </xs:complexType>    
</xs:element>    

提前致谢!

4

1 回答 1

1

你是如何做到这一点的?传统上是这样的

//initialize the client
SingleSignOn client = new SingleSignOnClient();
//initialize the request
authenticateToNCIDv2Request request = new authenticateToNCIDv2Request();
//fill the request
request.AppID = "1234";
request.AppPassword = "appPW";
request.UserID = "testUser";
request.UserPassword = "userPW";
//initialize the response and fill it with response from method
authenticateToNCIDv2Response response = client.authenticateToNCIDv2(request);

从这里开始解析响应。请注意,我没有深入查看您的 wsdl 以查看我的代码是否准确

于 2012-10-17T17:10:53.027 回答