使用来自wsdl(noob)的c#来使用webservice

时间:2012-10-17 16:48:54

标签: c# web-services wsdl

我正在尝试编写一些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>    

                                                                                                                                                                           

提前致谢!

1 个答案:

答案 0 :(得分:1)

你是怎么做到这一点的? Traditionaly它就是这样的

//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以查看我的代码是否准确