I am having an issue with a WCF service working correctly. I am trying to create a duplex service but evertime I try to return a custom datatype it breaks the client side.
If I remove GetTestData everything works fine. When I add it everything breaks on the client side. It seems like I can fix it by unchecking "Reuse types in referenced assemblies", but I am not sure if there are negative side effects in doing this.
Here is the code
ITestService.cs
namespace MyApp.Server
{
[ServiceContract(Namespace = "http://www.mysite.net", CallbackContract = typeof(IDuplexTestClient))]
public interface ITestService
{
[OperationContract]
string Hello();
[OperationContract]
TestData GetTestData();
}
public interface IDuplexTestClient
{
[OperationContract(IsOneWay = true)]
void TestCallback(string message);
}
}
TestService.cs
namespace MyApp.Server
{
[ServiceBehavior(Namespace = "http://www.mysite.net")]
public class TestService : ITestService, ICrossDomainPolicyResponder
{
public string Hello()
{
return "Hello";
}
public TestData GetTestData()
{
return new TestData();
}
#region ICrossDomainPolicyResponder Members
public Stream GetSilverlightPolicy()
{
string result = @"<?xml version=""1.0"" encoding=""utf-8""?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers=""*"">
<domain uri=""*""/>
</allow-from>
<grant-to>
<resource path=""/"" include-subpaths=""true""/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>";
return StringToStream(result);
}
public Stream GetFlashPolicy()
{
string result = @"<?xml version=""1.0""?>
<!DOCTYPE cross-domain-policy SYSTEM ""http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"">
<cross-domain-policy>
<allow-access-from domain=""*"" />
</cross-domain-policy>";
return StringToStream(result);
}
private Stream StringToStream(string result)
{
WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
return new MemoryStream(Encoding.UTF8.GetBytes(result));
}
#endregion
}
}
TestData.cs
namespace MyApp.SDK
{
[DataContract(Namespace = "http://www.mysite.net")]
public class TestData
{
[DataMember]
public string TestString { get; set; }
}
}
I'm still not 100% sure what is going on here but I found a solution that works for me. I am able to use the "Reuse types in specified referenced assemblies" to get the functionality I need. This fixed the problem but still allows me to share the MyApp.SDK classes between the client and server.