locked
An unhandled exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll RRS feed

  • Question

  • User-1834799348 posted

    Hi ,

    Can I get help hot to solve .Im getting  above exception.

    public void ValidateTest()

    {

    var o = new Program();//here exception.

    var n = o.NewOrderRequest();

     

    Assert.AreEqual(s, n);

    }

    public class Program

    {

    ServService.ESoapClient vNewRequest = new ESoapClient();//Exception here.Here im trying get  service reference of webservice

    ...

    }

    Monday, November 4, 2019 5:43 PM

All replies

  • User-1834799348 posted

    I have this output .From this below xml I want to show only netoutcome=block.I don't know how to get it in the above code. this output comes in n variable.

    <OAIForEFW>

    <SystemResult _NetOutcome="BLOCK">...<  </SystemResult><OAIForEFW>

    Can I get some help.Thank you.

    Monday, November 4, 2019 6:16 PM
  • User475983607 posted

    You're trying to unit test a service reference which is not a valid unit test.  The unit test should test the logic that handles the service response by using a mock object.  Or test the WCF service implementation.

    Monday, November 4, 2019 6:23 PM
  • User-1834799348 posted

    ok before doing unit test I want to read inner element in xml  "netoutcome==block" then I can do the unit test.I wrote below code  but not able read the values

    public void ValidateTestFail()

    {

    var o = new Program();

    var n = o.NewOrderRequest();

    //using (var reader = XmlReader.Create(new StringReader(n.ToString())))

    //{

    // while (reader.Read())

    // {

    // if (reader.IsStartElement())

    // {

    // var attr = reader["OPIForEW"];

    // if (attr == "OPIForEW" )

    // {

    // if (reader.ReadToDescendant("_NetOutcome"))

    // {

    // reader.Read();

    // result = reader.Value;

    // break;

    // }

    // }

    // //if (attr == "_NetOutcome" && attr == "Block")

    // //{

    // // if (reader.ReadToDescendant("_NetOutcome"))

    // // {

    // // reader.Read();

    // // result = reader.Value;

    // // break;

    // // }

    // //}

    // }

    // }

    //}

    var reader = XmlReader.Create(new StringReader(n.ToString()));

    while (reader.Read())

    {

    }

    //Assert.AreEqual(n, s);

    }

    Monday, November 4, 2019 7:02 PM
  • User475983607 posted

    cvm321

    ok before doing unit test I want to read inner element in xml  "netoutcome==block" then I can do the unit test.I wrote below code  but not able read the values

    You are showing what looks like a service reference.  Generally the service reference deserializes XML (SOAP) and returns a strong type.  The mock should be a type not XML.  As written you are testing XML deserialization and/or XPath which has already been tested by Microsoft.

    Monday, November 4, 2019 7:23 PM