c #asmx客户端无法解组soap响应

时间:2016-10-24 11:59:26

标签: c# web-services wsdl marshalling asmx

我通过我的c#代码向Web服务发送请求。我能够在Fiddler中获得成功的请求和响应,并且还可以通过使用Fiddler的请求在SOAP UI中获得响应。但是在代码调试时,我将Response对象视为null“对象引用未设置为对象的实例”。  下面是我的c#代码:

public List<MailOutResponse> SendMailOrder(OrderEntity objOrderEnty)
    {
        List<MailOutResponse> lsteDemandResp = new List<MailOutResponse>();
        MailOutResponse objMailOutResp = null;
        string strPayloadType = objOrderEnty.PayloadType;
        string strMailType = objOrderEnty.MailType;
        eDemandService.Order eDemandOrder = null;
        try
        {
                LogProcess.WriteLog("Processing item--" + objOrderEnty.OrderItemList[0].UniqueId.ToString(), strMailType);
                eDemandOrder = new eDemandService.Order();
                eDemandOrder.UniqueOrderId = "UD" + objOrderEnty.OrderItemList[0].UniqueId.Replace(":", "").ToString();
                eDemandOrder.OrderHeader = createOrderHeader(objOrderEnty.OrderItemList[0]);
                eDemandService.OrderOrderItem orderItem = new eDemandService.OrderOrderItem();
                orderItem.ItemDetailStructure = new eDemandService.OrderOrderItemItemDetailStructure();
                orderItem.ItemDetailStructure.Item = strItemDetailStructVal;

                orderItem.UniqueOrderItemId = "OB" + objOrderEnty.OrderItemList[0].UniqueId.Replace(":", "");

                XmlDocument f = new XmlDocument();
                f = (XmlDocument)GetXmlNode(objOrderEnty.OrderItemList[0].PayLoad.Root);
                orderItem.PreFillPayload = f.DocumentElement;

                eDemandService.OrderOrderItem[] orderItems = new eDemandService.OrderOrderItem[1];
                orderItems[0] = orderItem;
                eDemandOrder.OrderDetail = orderItems;

            eDemandService.eDemand eDemand = new eDemandService.eDemand();
            eDemandService.edemandService edemandClient = new eDemandService.edemandService();

            eDemand.PayloadType = strPayloadType;
            eDemand.OriginatingSysRef = strOriginatingSysRef;
            eDemand.Order = eDemandOrder;

            eDemandService.eDemandResponse myResponse = new eDemandService.eDemandResponse();

            LogProcess.WriteLog("---------------Calling the eDemand service-----------------", strMailType);
            LogProcess.WriteLog(eDemand, DateTime.Now.Ticks.ToString(), strMailType);

            myResponse = edemandClient.e(eDemand);
            LogProcess.WriteLog(myResponse, DateTime.Now.Ticks.ToString(), strMailType);
            eDemandService.eDemandResponseOrderResponse[] rspns = new eDemandService.eDemandResponseOrderResponse[1] ;
            rspns = myResponse.OrderResponse;

            for (int i = 0; i < myResponse.OrderResponse.Length; i++)
            {
                objMailOutResp = new MailOutResponse();
                if (myResponse.OrderResponse.Length > 0)
                {
                    objMailOutResp.OrderResponseCode = myResponse.OrderResponse[i].OrderResponseCode;
                    objMailOutResp.ExecutionStatus = myResponse.OrderResponse[i].OrderResponseText;
                    if (myResponse.OrderResponse[i].OrderResponseCode == "2000")
                    {
                        if (myResponse.OrderResponse[i].OrderItemResponse[0] != null)
                        {
                            objMailOutResp.ResponseUID = myResponse.OrderResponse[i].OrderItemResponse[0].UniqueOrderItemId;
                            objMailOutResp.IDBID = myResponse.OrderResponse[i].OrderItemResponse[0].IDBID;
                        }
                    }

                }
                lsteDemandResp.Add(objMailOutResp);
            }
        }
        catch (Exception ex)
        {
            LogProcess.WriteLog("Error calling the eDemand service - " + ex.Message, strMailType);
        }

        return lsteDemandResp;
    }

这是wsdl响应类型:

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
    [return: System.Xml.Serialization.XmlElementAttribute("eDemandResponse", Namespace="http://edemand.fmr.com/eDemandRequest")]
    public eDemandResponse e([System.Xml.Serialization.XmlElementAttribute(Namespace="http://edemand.fmr.com/eDemandRequest")] eDemand eDemand) {
        object[] results = this.Invoke("e", new object[] {
                    eDemand});
        return ((eDemandResponse)(results[0]));
    }

这就是我从小提琴手那里得到的:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

<SOAP-ENV:Header/>
<SOAP-ENV:Body>
  <Resp:eDemandResponse B2BID="3322277" xmlns:Resp="http://eDemand.fmr.com/eDemandResponse">
     <StatusCode>2000</StatusCode>
     <StatusText>Processing was successful</StatusText>
     <OrderResponse UniqueOrderId="UDTA_ID429636">
        <OrderResponseCode>2000</OrderResponseCode>
        <OrderResponseText>Processing was successful</OrderResponseText>
        <OrderItemResponse IDBID="154464360" UniqueOrderItemId="OBTA_ID429636">
           <DeliveryMethod>
              <Delivery type="Postal">
                 <ExecutionStatus>
                    <ReturnCode>2000</ReturnCode>
                    <ReturnText>Postal Delivery Method Successful</ReturnText>
                 </ExecutionStatus>
              </Delivery>
           </DeliveryMethod>
        </OrderItemResponse>
     </OrderResponse>
  </Resp:eDemandResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>  

我的wldl网址是:https://dgedmdrtp1.fmr.com:12000/eDemand/edemand/

所以基本上当我调试客户端时,我看到请求进入正确填充,但是响应没有被解组到创建Web引用时生成的存根响应对象。

0 个答案:

没有答案