Reputation: 3333
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?
Upvotes: 4
Views: 156
Reputation: 453
Yes, i am also faced same issue and solved it.
I've solved in two ways.
While adding Service Reference -> Check 'Always generate message contract' under DataType option
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.
Upvotes: 0
Reputation: 1105
I do not know if this would cause this problem, but I would mark my similarly structured MessageContract up as follows:
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.
Upvotes: 3