C#WSDL返回XML响应,但变量仍为null

时间:2018-08-10 15:22:09

标签: c# xml wsdl

我有一个返回Xml响应的WSDL,但是当我尝试将其分配给响应变量时,该对象仍然为空。

这是我的代码,调用Web服务并尝试将响应分配给我的变量:

CustomerReq request = new CustomerReq();
            request.DayPhone = "";
            request.OrganizationCode = "JY-US";
            request.EmailID = "sampleemail@se.com";

            getCustomerInfoResponse response = new getCustomerInfoResponse();


            WSA_CUSTOMER_LOOKUP_OMSClient client = new WSA_CUSTOMER_LOOKUP_OMSClient();
            client.Endpoint.EndpointBehaviors.Add(new FaultFormatingBehavior());

            client.Open();

            response.getCustomerInfoResponse1 = client.getCustomerInfo(request);
            client.Close();

这是Xml请求:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005    /05/addressing/none">http://WSA_CUSTOMER_LOOKUP_OMS/getCustomerInfo</Action>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<getCustomerInfo OrganizationCode="JY-US" DayPhone="" EmailID="sampleemail@se.com" xmlns="http://WSA_CUSTOMER_LOOKUP_OMS" />
</s:Body>
</s:Envelope>

我收到的回复:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" />
<soapenv:Body>
<out:getCustomerInfoResponse xmlns:out="http://WSA_CUSTOMER_LOOKUP_OMS">
<CustomerList TotalNumberOfRecords="1">
<Customer AssignedReps="0" BuyerOrganizationCode="" CanConsumeSupplementalCapacity="N" Createprogid="SterlingHttpTester" Createts="2015-03-04T10:09:49-06:00" Createuserid="CustomerName" CustomerID="100207932" CustomerKey="20150304100950117737467" CustomerType="02" ExternalCustomerID="" Lockid="113" MaxAssignRepsOrTeams="0" MaxModifyTS="2018-04-20T15:36:41-05:00" Modifyprogid=".YRCApp" Modifyts="2018-04-20T15:36:41-05:00" Modifyuserid="CustomerName" OrganizationCode="JY-US" RegisteredDate="2015-03-04T10:09:49-06:00" RootCustomerKey="20150304100950117737467" SendsAsn="N" SendsCommitment="N" SendsFuncAck="N" SlotPreferenceType="NONE" Status="10">
<Extn ExtnAccountAllowed="N" ExtnCustomerCreditRating="N" ExtnCustomerCrossRefItem="N" ExtnDirectMailFlag="Y" ExtnEmplFeed="N" ExtnLastOrdDate="2017-10-13" ExtnPayrollDeductionAllowed="N" ExtnPrepayAllowed="N" ExtnRequiredPONumber="N" ExtnShipComplete="N" ExtnShipToEmpl="N" ExtnSubscrStatus="0" ExtnTotCustValue="0.00" ExtnTotalOrders="0" ExtnWebAccountAllowed="N" ExtnWebCustomerID="CustomerName@genesco.com" ExtnWebEnabled="N" ExtnWebPrepayAllowed="N">
</Extn>
<CustomerContactList>
<CustomerContact Company="" Createprogid="SterlingHttpTester" Createts="2015-03-04T10:09:49-06:00" Createuserid="CustomerName" CustomerContactID="100208103" CustomerContactKey="20150304100950117737468" CustomerKey="20150304100950117737467" DayFaxNo="" DayPhone="5555555555" EmailID="CustomerName@genesco.com" EveningFaxNo="" EveningPhone="" FirstName="A" LastName="T" Lockid="3" MiddleName="" MobilePhone="" Modifyprogid="CreateOrder" Modifyts="2017-04-26T08:25:08-05:00" Modifyuserid="CreateOrder" Title="" UserID="">
<CustomerAdditionalAddressList>
<CustomerAdditionalAddress AddressType="" Createprogid="SterlingHttpTester" Createts="2015-03-04T10:09:50-06:00" Createuserid="CustomerName" CustomerAdditionalAddressID="100238485" CustomerAdditionalAddressKey="20150304100950117737470" CustomerContactKey="20150304100950117737468" CustomerKey="20150304100950117737467" IsBillTo="Y" IsDefaultBillTo="Y" IsDefaultShipTo="Y" IsInherited="N" IsShipTo="Y" Lockid="4" Modifyprogid="CreateOrder" Modifyts="2017-04-26T14:48:05-05:00" Modifyuserid="CreateOrder" PersonInfoKey="20170426082509190364347">
<PersonInfo AddressLine1="1415 Rd Pike" AddressLine2="" AddressLine3="" AddressLine4="" AddressLine5="" AddressLine6="" AlternateEmailID="" Beeper="" City="SomeCity" Company="" Country="US" Createprogid="CreateOrder" Createts="2017-04-26T08:25:08-05:00" Createuserid="CreateOrder" DayFaxNo="" DayPhone="5555555555" Department="" EMailID="CustomerName@genesco.com" ErrorTxt="" EveningFaxNo="" EveningPhone="" FirstName="A" HttpUrl="" JobTitle="" LastName="T" Lockid="0" MiddleName="" MobilePhone="" Modifyprogid="CreateOrder" Modifyts="2017-04-26T08:25:08-05:00" Modifyuserid="CreateOrder" OtherPhone="" PersonID="" PersonInfoKey="20170426082509190364347" PreferredShipAddress="" ShortZipCode="37217" State="TN" Suffix="" Title="" UseCount="0" VerificationStatus="" ZipCode="37217" isHistory="N">
<Extn ExtnNormAddLine1="1415 Rd PIKE" ExtnNormCity="SomeCity" ExtnNormState="TN" ExtnNormZipCode="#####">
</Extn>
</PersonInfo>
</CustomerAdditionalAddress>
</CustomerAdditionalAddressList>
</CustomerContact>
</CustomerContactList>
<CustomerPaymentMethodList>
<CustomerPaymentMethod AvailableAccountBalance="0" Createprogid=".YRCApp" Createts="2015-05-11T14:24:27-05:00" Createuserid="CustomerName" CreditCardExpDate="" CreditCardName="" CreditCardNo=" " CreditCardType="" CustomerAccountNo=" " CustomerContactKey="" CustomerKey="20150304100950117737467" CustomerPaymentMethodKey="20150511142427123647013" DisplayCreditCardNo="" DisplayCustomerAccountNo="" DisplayPaymentReference1="4444" DisplayPrimaryAccountNo="4444" FirstName="" IsDefaultMethod="N" IsInherited="N" LastName="" Lockid="0" MiddleName="" Modifyprogid=".YRCApp" Modifyts="2015-05-11T14:24:27-05:00" Modifyuserid="CustomerName" PaymentReference1="4444" PaymentReference2="60.0" PaymentReference3="" PaymentType="CHECK" PaymentTypeGroup="OTHER" PrimaryAccountNo="4444">
</CustomerPaymentMethod>
</CustomerPaymentMethodList>
</Customer>
<Customer AssignedReps="0" BuyerOrganizationCode="" CanConsumeSupplementalCapacity="N" Createprogid=".YRCApp" Createts="2018-08-03T07:15:00-05:00" Createuserid="CustomerName" CustomerID="100272221" CustomerKey="20180803071500281776624" CustomerType="02" ExternalCustomerID="" Lockid="0" MaxAssignRepsOrTeams="0" MaxModifyTS="2018-08-03T07:15:00-05:00" Modifyprogid=".YRCApp" Modifyts="2018-08-03T07:15:00-05:00" Modifyuserid="CustomerName" OrganizationCode="JY-US" RegisteredDate="2018-08-03T07:15:00-05:00" RootCustomerKey="20180803071500281776624" SendsAsn="N" SendsCommitment="N" SendsFuncAck="N" SlotPreferenceType="NONE" Status="10">
<Extn ExtnAccountAllowed="N" ExtnCustomerCreditRating="N" ExtnCustomerCrossRefItem="N" ExtnDirectMailFlag="N" ExtnEmplFeed="N" ExtnPayrollDeductionAllowed="N" ExtnPrepayAllowed="N" ExtnRequiredPONumber="N" ExtnShipComplete="N" ExtnShipToEmpl="N" ExtnSubscrStatus="0" ExtnTotCustValue="0.00" ExtnTotalOrders="0" ExtnWebAccountAllowed="N" ExtnWebEnabled="N" ExtnWebPrepayAllowed="N">
</Extn>
<CustomerContactList>
<CustomerContact Company="" Createprogid=".YRCApp" Createts="2018-08-03T07:15:00-05:00" Createuserid="CustomerName" CustomerContactID="100272403" CustomerContactKey="20180803071501281776625" CustomerKey="20180803071500281776624" DayFaxNo="" DayPhone="5555555555" EmailID="CustomerName@genesco.com" EveningFaxNo="" EveningPhone="" FirstName="Amber" LastName="T" Lockid="0" MiddleName="" MobilePhone="" Modifyprogid=".YRCApp" Modifyts="2018-08-03T07:15:00-05:00" Modifyuserid="CustomerName" Title="" UserID="">
<CustomerAdditionalAddressList>
<CustomerAdditionalAddress AddressType="" Createprogid=".YRCApp" Createts="2018-08-03T07:15:00-05:00" Createuserid="CustomerName" CustomerAdditionalAddressID="100318471" CustomerAdditionalAddressKey="20180803071501281776627" CustomerContactKey="20180803071501281776625" CustomerKey="20180803071500281776624" IsBillTo="Y" IsDefaultBillTo="Y" IsDefaultShipTo="Y" IsInherited="N" IsShipTo="Y" Lockid="0" Modifyprogid=".YRCApp" Modifyts="2018-08-03T07:15:00-05:00" Modifyuserid="CustomerName" PersonInfoKey="20180803071501281776626">
<PersonInfo AddressLine1="#### Rd Pike" AddressLine2="" AddressLine3="" AddressLine4="" AddressLine5="" AddressLine6="" AlternateEmailID="" Beeper="" City="SomeCity" Company="" Country="US" Createprogid=".YRCApp" Createts="2018-08-03T07:15:00-05:00" Createuserid="CustomerName" DayFaxNo="" DayPhone="5555555555" Department="" EMailID="CustomerName@genesco.com" ErrorTxt="" EveningFaxNo="" EveningPhone="" FirstName="Amber" HttpUrl="" IsCommercialAddress="N" JobTitle="" LastName="T" Lockid="0" MiddleName="" MobilePhone="" Modifyprogid=".YRCApp" Modifyts="2018-08-03T07:15:00-05:00" Modifyuserid="CustomerName" OtherPhone="" PersonID="" PersonInfoKey="20180803071501281776626" PreferredShipAddress="" ShortZipCode="37217" State="TN" Suffix="" Title="" UseCount="0" VerificationStatus="" ZipCode="37217-2829" isHistory="N">
<Extn>
</Extn>
</PersonInfo>
</CustomerAdditionalAddress>
</CustomerAdditionalAddressList>
</CustomerContact>
</CustomerContactList>
<CustomerPaymentMethodList>
</CustomerPaymentMethodList>
</Customer>
</CustomerList>
</out:getCustomerInfoResponse>
</soapenv:Body>
</soapenv:Envelope>

App.config中的终结点:

<endpoint address="http://som2:7803/WSA_CUSTOMER_LOOKUP_OMS"
            binding="basicHttpBinding" bindingConfiguration="WSA_CUSTOMER_LOOKUP_OMSHttpBinding"
            contract="OMSCustomerLookup.WSA_CUSTOMER_LOOKUP_OMS" name="WSA_CUSTOMER_LOOKUP_OMSHttpPort" />

以及定义:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class getCustomerInfoResponse {

    [System.ServiceModel.MessageBodyMemberAttribute(Name="getCustomerInfoResponse", Namespace="http://WSA_CUSTOMER_LOOKUP_OMS", Order=0)]
    public OMSWebServicesTest.OMSCustomerLookup.CustomerResp getCustomerInfoResponse1;

    public getCustomerInfoResponse() {
    }

    public getCustomerInfoResponse(OMSWebServicesTest.OMSCustomerLookup.CustomerResp getCustomerInfoResponse1) {
        this.getCustomerInfoResponse1 = getCustomerInfoResponse1;
    }
}

我已经通过SOAP UI进行了测试,并且可以正常工作,并且Xml响应看起来是正确的,但是它不允许我将其分配给响应变量,并且不会引发任何错误。任何解决此问题的想法将不胜感激,如果需要提供更多详细信息,也请告知我。

1 个答案:

答案 0 :(得分:0)

存在架构不匹配,已解决。