How to fix 'Cannot convert MWArray to requested type"

3 visualizaciones (últimos 30 días)
Charlie Peppler
Charlie Peppler el 2 de En. de 2019
I'm starting to set up a WCF Server for a Matlab application, and would like to receive a struct back using the Microsoft WCF Test Client. I need help passing a Matlab struct back successfully.
I am using Windows 10, VS 2017, Community edition. I have been able to successfully communicate across WCF using a simple string reply. I can pass data into Matlab, and generate a simple graph. However, when I try using the Matlab return through a struct, I can not seem to get past the error described below.
Matlab Function:
function y = callMATLABfunction( x )
clearvars -except x; close all;
if nargin == 1 && ~isempty(x)
if isnumeric(x)
[...]
y.Completion = 1;
y.Result = 'FirstCompletion';
y.Message = 'Success';
else
[...]
y.Completion = 1;
y.Result = 'SecondCompletion';
y.Message = 'Success';
end
else
y.Completion = 0;
y.Result = 'Error';
y.Message = 'Please supply one input variable';
end
end
IMatlabInterface.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
using System.Text;
using System.Threading.Tasks;
namespace MatlabSvc
{
[ServiceContract]
public interface IMatlabInterface
{
[OperationContract(Name = "callMATLABfunction_1")]
y callMATLABfunction(System.Double x);
[OperationContract(Name = "callMATLABfunction_2")]
y callMATLABfunction(System.String x);
}
[KnownType(typeof(y))]
[DataContract]
public class y
{
[DataMember]
public double Completion { get; set; }
[DataMember]
public string Result { get; set; }
[DataMember]
public string Message { get; set; }
}
}
I expected to see the return struct in Microsoft WCF Test Client. Instead, I get:
Cannot convert MWArray to requested type
Server stack trace: at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter) at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at IMatlabInterface.callMATLABfunction_1(Double x) at MatlabInterfaceClient.callMATLABfunction_1(Double x)
Is it possible to pass a struct back through to C# using type safe interface?

Respuestas (0)

Categorías

Más información sobre Deploy to .NET Applications Using MWArray API en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by