Question

I have the following wcf service:

[ServiceContract]
public interface IUnitTestingService
{
    [OperationContract]
    TestsResult ExecuteUnitTests(UploadRequest unitTestsExecutionData);

}


// Use a data contract as illustrated in the sample below to add composite types to service operations.

public class TestResult
{
    public enum TestRunResult
    {
        Passed=1,
        Failed=2,
        Exception=3
    }

    public string TestName { get; set; }

    public string StartTime { get; set; }

    public string EndTime { get; set; }

    public string Result { get; set; }

}

[MessageContract(WrapperName = "TestResult"), DataContract]
public class TestsResult
{
   [MessageHeader, DataMember]
    public List<TestResult> Results { get; set; }

    [MessageHeader, DataMember]
   public int TotalExecutedTests { get; set; }

   [MessageHeader, DataMember]
    public int TotalPassedTests { get; set; }

    [MessageHeader]
    public int TotalFailedTests { get; set; }
}

[MessageContract]
public class UploadRequest
{
    [MessageHeader(MustUnderstand = true)]
    public UnitTestingFrameworkType UnitTestingFrameworkType { get; set; }

    [MessageBodyMember(Order = 1)]
    public Stream Stream { get; set; }
}

However when i generate wcf client class via add service refference I get this:

 public UTS.ServiceReference1.TestResult[] ExecuteUnitTests(UTS.ServiceReference1.UnitTestingFrameworkType UnitTestingFrameworkType, System.IO.Stream Stream, out int TotalExecutedTests, out int TotalFailedTests, out int TotalPassedTests)

instead of this:

TestsResult ExecuteUnitTests(UploadRequest unitTestsExecutionData);

Why?

Was it helpful?

Solution

I do not know if this would cause this problem, but I would mark my similarly structured MessageContract up as follows:

  1. Using the [MessageHeader] attribute is enough on MessageHeader members.
  2. If the contract TestsResults is not a top level contract, I would mark it up as a DataContract with DataMember attributes only.

EDIT: 3. TestResult should also be a DataContract, with all members marked up with DataMember. Your enum must be marked up with the EnumMember attribute.

I hope this helps.

OTHER TIPS

Yes, i am also faced same issue and solved it.

I've solved in two ways.

  1. While adding Service Reference -> Check 'Always generate message contract' under DataType option

  2. Add the following code in your client
    BasicHttpBinding myBinding = new BasicHttpBinding();
    ChannelFactory factory = new ChannelFactory(myBinding, new EndpointAddress(""));
    IContractName client = factory.CreateChannel();

I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top