我使用svcutil生成以下代码:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.239
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace System.Net
{
using System.Runtime.Serialization;
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="EndPoint", Namespace="http://schemas.datacontract.org/2004/07/System.Net")]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(System.Net.IPEndPoint))]
public partial class EndPoint : object, System.Runtime.Serialization.IExtensibleDataObject
{
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
public System.Runtime.Serialization.ExtensionDataObject ExtensionData
{
get
{
return this.extensionDataField;
}
set
{
this.extensionDataField = value;
}
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="IPEndPoint", Namespace="http://schemas.datacontract.org/2004/07/System.Net")]
public partial class IPEndPoint : System.Net.EndPoint
{
private System.Net.IPAddress m_AddressField;
private int m_PortField;
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public System.Net.IPAddress m_Address
{
get
{
return this.m_AddressField;
}
set
{
this.m_AddressField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public int m_Port
{
get
{
return this.m_PortField;
}
set
{
this.m_PortField = value;
}
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="IPAddress", Namespace="http://schemas.datacontract.org/2004/07/System.Net")]
public partial class IPAddress : object, System.Runtime.Serialization.IExtensibleDataObject
{
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
private long m_AddressField;
private System.Net.Sockets.AddressFamily m_FamilyField;
private int m_HashCodeField;
private ushort[] m_NumbersField;
private long m_ScopeIdField;
public System.Runtime.Serialization.ExtensionDataObject ExtensionData
{
get
{
return this.extensionDataField;
}
set
{
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public long m_Address
{
get
{
return this.m_AddressField;
}
set
{
this.m_AddressField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public System.Net.Sockets.AddressFamily m_Family
{
get
{
return this.m_FamilyField;
}
set
{
this.m_FamilyField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public int m_HashCode
{
get
{
return this.m_HashCodeField;
}
set
{
this.m_HashCodeField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public ushort[] m_Numbers
{
get
{
return this.m_NumbersField;
}
set
{
this.m_NumbersField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public long m_ScopeId
{
get
{
return this.m_ScopeIdField;
}
set
{
this.m_ScopeIdField = value;
}
}
}
}
namespace System.Net.Sockets
{
using System.Runtime.Serialization;
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="AddressFamily", Namespace="http://schemas.datacontract.org/2004/07/System.Net.Sockets")]
public enum AddressFamily : int
{
[System.Runtime.Serialization.EnumMemberAttribute()]
Unknown = -1,
[System.Runtime.Serialization.EnumMemberAttribute()]
Unspecified = 0,
[System.Runtime.Serialization.EnumMemberAttribute()]
Unix = 1,
[System.Runtime.Serialization.EnumMemberAttribute()]
InterNetwork = 2,
[System.Runtime.Serialization.EnumMemberAttribute()]
ImpLink = 3,
[System.Runtime.Serialization.EnumMemberAttribute()]
Pup = 4,
[System.Runtime.Serialization.EnumMemberAttribute()]
Chaos = 5,
[System.Runtime.Serialization.EnumMemberAttribute()]
NS = 6,
[System.Runtime.Serialization.EnumMemberAttribute()]
Ipx = 6,
[System.Runtime.Serialization.EnumMemberAttribute()]
Iso = 7,
[System.Runtime.Serialization.EnumMemberAttribute()]
Osi = 7,
[System.Runtime.Serialization.EnumMemberAttribute()]
Ecma = 8,
[System.Runtime.Serialization.EnumMemberAttribute()]
DataKit = 9,
[System.Runtime.Serialization.EnumMemberAttribute()]
Ccitt = 10,
[System.Runtime.Serialization.EnumMemberAttribute()]
Sna = 11,
[System.Runtime.Serialization.EnumMemberAttribute()]
DecNet = 12,
[System.Runtime.Serialization.EnumMemberAttribute()]
DataLink = 13,
[System.Runtime.Serialization.EnumMemberAttribute()]
Lat = 14,
[System.Runtime.Serialization.EnumMemberAttribute()]
HyperChannel = 15,
[System.Runtime.Serialization.EnumMemberAttribute()]
AppleTalk = 16,
[System.Runtime.Serialization.EnumMemberAttribute()]
NetBios = 17,
[System.Runtime.Serialization.EnumMemberAttribute()]
VoiceView = 18,
[System.Runtime.Serialization.EnumMemberAttribute()]
FireFox = 19,
[System.Runtime.Serialization.EnumMemberAttribute()]
Banyan = 21,
[System.Runtime.Serialization.EnumMemberAttribute()]
Atm = 22,
[System.Runtime.Serialization.EnumMemberAttribute()]
InterNetworkV6 = 23,
[System.Runtime.Serialization.EnumMemberAttribute()]
Cluster = 24,
[System.Runtime.Serialization.EnumMemberAttribute()]
Ieee12844 = 25,
[System.Runtime.Serialization.EnumMemberAttribute()]
Irda = 26,
[System.Runtime.Serialization.EnumMemberAttribute()]
NetworkDesigners = 28,
[System.Runtime.Serialization.EnumMemberAttribute()]
Max = 29,
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="IConnectionHost", CallbackContract=typeof(IConnectionHostCallback), SessionMode=System.ServiceModel.SessionMode.Required)]
public interface IConnectionHost
{
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IConnectionHost/OpenTunnel", ReplyAction="http://tempuri.org/IConnectionHost/OpenTunnelResponse")]
bool OpenTunnel(int serverPort);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IConnectionHost/CloseTunnel", ReplyAction="http://tempuri.org/IConnectionHost/CloseTunnelResponse")]
bool CloseTunnel(int serverPort);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IConnectionHost/DisconnectAtHost", ReplyAction="http://tempuri.org/IConnectionHost/DisconnectAtHostResponse")]
bool DisconnectAtHost(int serverPort, System.Net.IPEndPoint client);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IConnectionHost/Reply", ReplyAction="http://tempuri.org/IConnectionHost/ReplyResponse")]
int Reply(int serverPort, System.Net.IPEndPoint client, [System.ServiceModel.MessageParameterAttribute(Name="reply")] byte[] reply1);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface IConnectionHostCallback
{
[System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="http://tempuri.org/IConnectionHost/Relay")]
void Relay(int serverPort, System.Net.IPEndPoint client, byte[] message);
[System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="http://tempuri.org/IConnectionHost/DisconnectAtClient")]
void DisconnectAtClient(int serverPort, System.Net.IPEndPoint client);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface IConnectionHostChannel : IConnectionHost, System.ServiceModel.IClientChannel
{
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class ConnectionHostClient : System.ServiceModel.DuplexClientBase<IConnectionHost>, IConnectionHost
{
public ConnectionHostClient(System.ServiceModel.InstanceContext callbackInstance) :
base(callbackInstance)
{
}
public ConnectionHostClient(System.ServiceModel.InstanceContext callbackInstance, string endpointConfigurationName) :
base(callbackInstance, endpointConfigurationName)
{
}
public ConnectionHostClient(System.ServiceModel.InstanceContext callbackInstance, string endpointConfigurationName, string remoteAddress) :
base(callbackInstance, endpointConfigurationName, remoteAddress)
{
}
public ConnectionHostClient(System.ServiceModel.InstanceContext callbackInstance, string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(callbackInstance, endpointConfigurationName, remoteAddress)
{
}
public ConnectionHostClient(System.ServiceModel.InstanceContext callbackInstance, System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(callbackInstance, binding, remoteAddress)
{
}
public bool OpenTunnel(int serverPort)
{
return base.Channel.OpenTunnel(serverPort);
}
public bool CloseTunnel(int serverPort)
{
return base.Channel.CloseTunnel(serverPort);
}
public bool DisconnectAtHost(int serverPort, System.Net.IPEndPoint client)
{
return base.Channel.DisconnectAtHost(serverPort, client);
}
public int Reply(int serverPort, System.Net.IPEndPoint client, byte[] reply1)
{
return base.Channel.Reply(serverPort, client, reply1);
}
}
然后在Mathematica(8)&amp; .NET / Link创建一个IPEndPoint对象:
ep // ClearAll
ep[port_] := NETNew["System.Net.IPEndPoint", NETNew["System.Net.IPAddress", {127, 0, 0, 1}], port_]
retargetedEndPoint=ep@900
并尝试致电:
.Reply(.,retargetedEndPoint,.)
问题是Mathematica IPEndPoint对象是真正的System.NET.IPEndPoint类型,而预期的对象是一些序列化表示!
答案 0 :(得分:1)
在System.Net命名空间中生成任何内容看起来不正确。我想也许您想使用svcutil的/reference:<file path>
选项,以便它知道在哪里查找现有类型。