1

I am writing for the first time something related to wcf, I did everything according to the documentation, etc., but I do not understand why my client does not want to receive data from the service. Moreover, it only accepts data, from the service itself I do not call methods in the client, does it mean that I have one-way wsHttpBinding?

The task is as follows: the service receives from the client the matrix size (5x5) and enum identifier for determining how to generate the matrix itself, a random matrix of the specified dimension is generated on the server and returns Matrix <double> to the client. Then this matrix will again be transferred to the service for operations with it. The problem is that I get the following message when the matrix is ​​returned to the client and the error is in the line where the GetMatrix method is called.

An error occurred while receiving the HTTP response to http://localhost:8080/WCF_TRSPO/Service1/. This could be due to the service endpoint binding not using the HTTP protocol.

ServiceTrace says me that error:

The message with To 'http://localhost:8080/WCF_TRSPO/Service1/mex/mex' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.

Look, if I pass to the client not the matrix, but null, then the client accepts it. The 5x5 matrix refuses. Similarly, Vector <double>. I don’t understand what the problem is, Google search did not return results. Give though directions where to look or where I was wrong?)

Service App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="WCF_TRSPO_Lib.Service1">
        <endpoint address="" binding="wsHttpBinding" contract="WCF_TRSPO_Lib.IService1">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/WCF_TRSPO/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

Client App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IService1" />
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8080/WCF_TRSPO/Service1/"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
                contract="ServiceReference1.IService1" name="WSHttpBinding_IService1">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

Service interface

[ServiceContract]
    public interface IService1
    {       

        [OperationContract]
        ObjectObgortka GetMatrixData(int n, MatrixEnum Letter);

Service Data source where data set return to client

[DataContract]    
    public class ObjectObgortka
    {
        public ObjectObgortka()
        {
            _Matrix = null;
            _Vector = null;
        }

        public Matrix<double> _Matrix;

        public Vector<double> _Vector;        


        [DataMember]
        public Matrix<double> Matrix { get { return _Matrix; } set { _Matrix = value; } }
        [DataMember]
        public Vector<double> Vector { get { return _Vector; } set { _Vector = value; } }

Service

public class Service1 : IService1
    {        
        public ObjectObgortka GetMatrixData(int n, MatrixEnum Letter)
        {
            MatrixFactory matrixFactory = new MatrixFactory();

            ObjectObgortka obgortka = new ObjectObgortka();
            Console.WriteLine(n);
            obgortka.Matrix = matrixFactory.GetMatrix(Letter, n);
            //obgortka.Matrix = null;           
            return obgortka;                   
        }

and Client

 public static void Main(string[] args)
        {
            //Step 1: Create an instance of the WCF proxy.
            Service1Client client = new Service1Client();

            // Step 2: Call the service operations.
            // Call the Add service operation.
            Console.Write("N: ");
            int n = Convert.ToInt32(Console.ReadLine());
            var matrixA = client.GetMatrixData(n, MatrixEnum.A); //here var is ObjectObgortka type from Servic
            Matrix<double> MatrixA = matrixA.Matrix;
  • New Message from Service Trace^ _Type 'MathNet.Numerics.LinearAlgebra.Double.DenseMatrix' with data contract name 'DenseMatrix:http://schemas.datacontract.org/2004/07/MathNet.Numerics.LinearAlgebra.Double' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer._ – Oleh Lysovych May 17 '20 at 17:19

1 Answers1

0

MathNet.Numerics.LinearAlgebra.Double.DenseMatrix' with data contract name 'DenseMatrix:schemas.datacontract.org/2004/07/…' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer

The error typically indicates that the server-side and the client-side failed to know how to serialize and deserialize the complex data type.
Since the Maxtrix<double>, Vector<double> cannot be recognized by WCF, we have to tell him what the data type structure is and how to serialize it into XML(the payload in HTTP). Please consider to decorate the complex type with DataContract attribute and use Known type to specify the types that should be included for consideration during serialization in advance.

[DataContract]
[KnownType(typeof(CircleType))]
[KnownType(typeof(TriangleType))]
public class CompanyLogo2
{
    [DataMember]
    private Shape ShapeOfLogo;
    [DataMember]
    private int ColorOfLogo;
}
[DataContract]
public class Shape { }

[DataContract(Name = "Circle")]
public class CircleType : Shape { }

[DataContract(Name = "Triangle")]
public class TriangleType : Shape { }

For more details,
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-data-contracts
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/data-contract-known-types
Feel free to let me know if there is anything I can help with.

Abraham Qian
  • 7,117
  • 1
  • 8
  • 22