Serialize and deserialize params of secret type (class inside dll written by other) in SoapCore WCF? - asp.net-core

How can I deserialize / serialize object of secret class (inside dll provided by other) to XML format in WCF in .NET Core (using SoapCore)?

Related

.NET Core RC2 - Consuming External WCF

I'm looking to call a .NET 4.6 service inside my .NET Core RC2 app.
I have tested the service within the WCF Test Client supplied by Microsoft and it works fine, I would like to now consume it inside my .NET Core application but am unsure on how to do that.
I have tried using the svcutil to generate the service reference file but I'm guessing this isn't really designed for the new .NET framework as it uses IExtensibleDataObject which doesn't exist in Core and the namespace System.Runtime.Serialization which now seems to have split into Xml, Primitives and Json.
DOes anybody have a example how I could simply consume an external (Not within my project) WCF.
Many Thanks
Microsoft released "WCF Connected Service for .NET Core RC2 and ASP.NET Core RC2". It should do the job.
I used it to generate client code for my service and:
it uses these attributes on DataContract classes:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.2.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Person", Namespace="http://schemas.datacontract.org/2004/07/Mock")]
public partial class Person : object
It uses [System.Runtime.Serialization.DataMemberAttribute()] for DataContract properties
It uses these attributes to define service contract:
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.2.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="Mock.IMockService")]
public interface IMockService
This is a sample opertaion definition inside the contract interface:
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMockService/LookupPerson", ReplyAction="http://tempuri.org/IkMockService/LookupPersonResponse")]
System.Threading.Tasks.Task<Mock.LookupPersonResponse> LookupPersonAsync(Mock.LookupPersonRequest request);
To mark request and response objects it uses:
[System.ServiceModel.MessageContractAttribute(WrapperName="LookupPerson", WrapperNamespace="http://tempuri.org/", IsWrapped=true)]
public partial class LookupPersonRequest
And property of the request/response is annotated with:
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=0)]
public CepikMock.PersonSearchCriteria criteria;
Finally it generates basic IClientChannel interface
public interface IMockChannel : Mock.IMockService, System.ServiceModel.IClientChannel
{
}
And a ClientBase implementation
public partial class MockServiceClient : System.ServiceModel.ClientBase<Mock.IMockService>, Mock.IMockService
Inside the client class, each service method is exposed like this:
public System.Threading.Tasks.Task<Mock.LookupPersonResponse> LookupPersonAsync(Mock.LookupPersonRequest request)
{
return base.Channel.LookupPersonAsync(request);
}

What does your return type have to implement in order for Web API to magically serialize it?

I noticed that Web API can return a DataTable as JSON but balks when returning it as XML.
What is (or are) the base interface(s) that your objects should inherit from in order for Web API to automagically serialize them?
And why would it be able to serialize a given object as JSON but not XML?
ASP.NET Web API uses DataContractSerializer for XML and JSON.NET for JSON. So, the respective serialization requirements hold good with web API as well. Check out this and this.
DataTable should get serialized by DCS, since DataTable implements IXmlSerializable. If you want more control over how XML is produced, you can implement IXmlSerializable yourself.

How to stop wcf service generating entity framework references

I have a WCF service containing an entity framework project.
I also have DTO classes that I use to expose the data. The entity objects get mapped to DTO objects.
When I generate a service proxy I am seeing both the entity object and the DTO object.
If I have a table called Product I get a Product and a Product1 reference.
This didn't use to happen.
What have I done to cause this and how can I stop my entity objects being exposed?
More Info:
When EF generates a model object from the database, it adds a data contract attribute like this:
[EdmEntityTypeAttribute(NamespaceName="KernMobile_V5Model", Name="JobMaster")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class JobMaster : EntityObject
I assume this means that it will be exposed by the service?
The service only exposes objects that are used in the service operations, or are specified as a known type to be exposed.
If your client proxy is generating an object for these entity framework objects, you must be exposing them through your service somehow. This can be as request or response objects, or as properties on those objects.

Consuming Wcf from classic asp (with datacontract)

I'm currently developing a WCF service (Service.svc) and I would like to consume it with classic ASP. Naturally, i first checked how to on Google and Mdsn Library. I managed to connect my service.
But here is the problem, i can call simple method like :
string GetData(int i)
But I have some DataContracts too a methods signed like this :
IsAvailRef[] AreAvailable(MyInType data)
\With IsAvailRef as DataContract and so is MyInType.
And when I call these methods, I've an Asp error 'ASP 0106 : 80020005' saying "A data type not supported has been detected."
So here is my question : Can't we use DataContract with VB script ?
This is the signature of my function in the library generated by regasm.exe like explained in this article : http://msdn.microsoft.com/en-us/library/ms752245.aspx
[id(0x60020000)]
HRESULT AreReferencesAvailable([out, retval] SAFEARRAY(_IsAvailRef*)* pRetVal);
I believe DataContract is a class and is not a valid VBScript subtype:
http://www.csidata.com/custserv/onlinehelp/vbsdocs/vbs6.htm
You can probably call it's methods, however I doubt you can store it in a variant.

Client side code is not generated for XElement properties

My domain service has invoke operation method and returns a custom
type say 'User'. This class has many properties such as String,
Integer, Boolean, XElement. When I rebuild the solution to generate
client-side proxy, it generates code for the class User in the client
for all the properties, except for XElement. What is the fix for this?
Will RIA not generate any code for XNode or XElement types? Should
these elements be converted to String? Are there any fixes for this
error?
I'm using VS2010 SP1, .Net Framework 4, WCF RIA, Silverlight 5.
According to the Silverlight DataContract documentation, you can mark your classes as either opt-in using the DataContract/DataMember attributes or opt-out and rely on only serializing public scope class members. You need to show the code of the class you're having problems with to get better suggestions.