How to fix ''Cannot convert MWArray to requested type"












0















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'm following instructions provided by MATHWORKS:



https://www.mathworks.com/help/compiler_sdk/dotnet/create-windows-communications-foundation-based-components.html#bsuwtjv


I am using Windows 10, VS 2017, Community edition. For Matlab I am using:



<MathWorks_version_info>
<version>9.5.0.944444</version>
<release>R2018b</release>
<description></description>
<date>Aug 28 2018</date>
<checksum>1708982227</checksum>




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)










share|improve this question

























  • I have made a test ,even when I use c# struct or c# class or combine c#struct with c# class, I could call the service successfully. [DataContract] public struct Y { [DataMember] public double Completion; [DataMember] public string Result; [DataMember] public string Message; } Maybe the problem is with the convert from matlab type to c# type, you could refer to the link below link

    – Ackelry Xu
    Jan 3 at 7:34


















0















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'm following instructions provided by MATHWORKS:



https://www.mathworks.com/help/compiler_sdk/dotnet/create-windows-communications-foundation-based-components.html#bsuwtjv


I am using Windows 10, VS 2017, Community edition. For Matlab I am using:



<MathWorks_version_info>
<version>9.5.0.944444</version>
<release>R2018b</release>
<description></description>
<date>Aug 28 2018</date>
<checksum>1708982227</checksum>




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)










share|improve this question

























  • I have made a test ,even when I use c# struct or c# class or combine c#struct with c# class, I could call the service successfully. [DataContract] public struct Y { [DataMember] public double Completion; [DataMember] public string Result; [DataMember] public string Message; } Maybe the problem is with the convert from matlab type to c# type, you could refer to the link below link

    – Ackelry Xu
    Jan 3 at 7:34
















0












0








0








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'm following instructions provided by MATHWORKS:



https://www.mathworks.com/help/compiler_sdk/dotnet/create-windows-communications-foundation-based-components.html#bsuwtjv


I am using Windows 10, VS 2017, Community edition. For Matlab I am using:



<MathWorks_version_info>
<version>9.5.0.944444</version>
<release>R2018b</release>
<description></description>
<date>Aug 28 2018</date>
<checksum>1708982227</checksum>




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)










share|improve this question
















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'm following instructions provided by MATHWORKS:



https://www.mathworks.com/help/compiler_sdk/dotnet/create-windows-communications-foundation-based-components.html#bsuwtjv


I am using Windows 10, VS 2017, Community edition. For Matlab I am using:



<MathWorks_version_info>
<version>9.5.0.944444</version>
<release>R2018b</release>
<description></description>
<date>Aug 28 2018</date>
<checksum>1708982227</checksum>




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)







c# matlab wcf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 21:03







Charlie Peppler

















asked Jan 2 at 20:40









Charlie PepplerCharlie Peppler

13




13













  • I have made a test ,even when I use c# struct or c# class or combine c#struct with c# class, I could call the service successfully. [DataContract] public struct Y { [DataMember] public double Completion; [DataMember] public string Result; [DataMember] public string Message; } Maybe the problem is with the convert from matlab type to c# type, you could refer to the link below link

    – Ackelry Xu
    Jan 3 at 7:34





















  • I have made a test ,even when I use c# struct or c# class or combine c#struct with c# class, I could call the service successfully. [DataContract] public struct Y { [DataMember] public double Completion; [DataMember] public string Result; [DataMember] public string Message; } Maybe the problem is with the convert from matlab type to c# type, you could refer to the link below link

    – Ackelry Xu
    Jan 3 at 7:34



















I have made a test ,even when I use c# struct or c# class or combine c#struct with c# class, I could call the service successfully. [DataContract] public struct Y { [DataMember] public double Completion; [DataMember] public string Result; [DataMember] public string Message; } Maybe the problem is with the convert from matlab type to c# type, you could refer to the link below link

– Ackelry Xu
Jan 3 at 7:34







I have made a test ,even when I use c# struct or c# class or combine c#struct with c# class, I could call the service successfully. [DataContract] public struct Y { [DataMember] public double Completion; [DataMember] public string Result; [DataMember] public string Message; } Maybe the problem is with the convert from matlab type to c# type, you could refer to the link below link

– Ackelry Xu
Jan 3 at 7:34














0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012876%2fhow-to-fix-cannot-convert-mwarray-to-requested-type%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012876%2fhow-to-fix-cannot-convert-mwarray-to-requested-type%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith