Battling with BizTalk

Web service response

I started developing a new BizTalk application today which must call an existing web service. Unfortunately I didn't have access to the web service from my test environment so I had to create a test stub. The web service method I needed accepted a string and returned an object containing an int and a bool. My first step was to examine the wsdl of the existing web service to get a good idea of the type my stub should be returning. Because the input / output parameters were simple it was only ten minutes or so before I was able to run my first test. I dropped a trigger file into a receive folder, this was picked up by my new orchestration and my test stub web service was called. Of course nothing ever works first time and this was no exception. The SOAP adapter was throwing an error, complaining that the SOAP Body was empty. To aid my debugging I installed the Microsoft SOAP SDK - this contains a very helpful "trace utility" which allows you to view all data passed to and from the web service. To make this work I simply changed the send port to post to port 8080, this trace utility then logs the traffic before routing to the end destination - port 80. With the trace running I could see that the format of the returned XML was slightly different to that when I browsed to the asmx of the real web service. In particular, the body of the real web service contained looked as follows:
  <soap:Body>
    <PrepareFraudCheckResponse xmlns="http://direct.xxx.com/retail/services/paymentservices">
      <PrepareFraudCheckResponsMsg>
        <VelocityCheckMatchFound>boolean</VelocityCheckMatchFound>
        <BasketRiskAttribute>int</BasketRiskAttribute>
      </PrepareFraudCheckResponsMsg>
    </PrepareFraudCheckResponse>
  </soap:Body>
 
The body of the XML returned by my test stub was the same except rather than <PrepareFraudCheckResponsMsg>
 it was returning <PrepareFraudCheckResult>. This would explaing the error being thrown by the SOAP adapter, it would run an XSL query against the element it was expecting - nothing would be returned thefore it would complain that the body of the message was empty. To fix my test stub I needed to find out how to present the back the XML with the correct element name. In the end, the solution was straight-forward, I simply needed to add an attribute to the class of the object I was returning as follows:
 
[System.Xml.Serialization.XmlRoot("PrepareFraudCheckResponsMsg")]
 
I include the entire code listing for the web service stub below:
 
[WebService(Namespace = "http://direct.xxx.com/retail/services/paymentservices")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    [SoapDocumentServiceAttribute(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
    [Serializable]
    public class Service1 : System.Web.Services.WebService
    {
        [WebMethod]
        public ReturnType PrepareFraudCheck(string orderRef)
        //public string PrepareFraudCheck(string orderRef)
        {
            ReturnType rt = new ReturnType();
            rt.VelocityCheckMatchFound = true;
            rt.BasketRiskAttribute = 1;
            return rt;
            //return "<?xml version='1.0' encoding='UTF-8'?><Root> xmlns='http://direct.xxx.com/retail/services/paymentservices'> <VelocityCheckMatchFound>true</VelocityCheckMatchFound> <BasketRiskAttribute>1</BasketRiskAttribute></Root>";
        }
    }

    [System.Xml.Serialization.XmlRoot("PrepareFraudCheckResponsMsg")]
    public class ReturnType
    {
        private bool _velocityCheck = true;
        private int _riskLevel = 1;

        public bool VelocityCheckMatchFound
        {
            get
            {
                return true;
            }
            set
            {
                _velocityCheck = value;
            }
        }
        public int BasketRiskAttribute
        {
            get
            {
                return 1;
            }
            set
            {
                _riskLevel = value;
            }
        }
    }


Feedback

No comments posted yet.