我们正在尝试使用 System.ServiceModel.dll 对我们的 WCF Web 服务进行调用。我们的应用程序构建和部署正常,但在运行时会生成以下错误..
System.MissingMethodException: The method 'System.Void System.ServiceModel.BasicHttpBinding::.ctor()' has no implementation.
该应用程序使用位于 Assets/Plugins/WSA/x86/ 中的 System.ServiceModel.dll 构建,并配置为在 Hololens 平台 (WSAPlayer) 上使用,如下所示。如何解决缺少方法异常?
我们尝试使用“C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework”和“C:\Program Files\Unity\Editor\Data\”中可用的 System.ServiceModel.dll 的不同变体,但没有成功. 不确定这个错误是如何开始的,因为我们的应用程序过去可以毫无复杂地工作。
客户端调用代码
#if !UNITY_EDITOR
public static Service1Client client;
#endif
void Awake()
{
#if !UNITY_EDITOR
client = new Service1Client(new BasicHttpBinding(),
new EndpointAddress("http://myServer/myService/myService.Service1.svc"));
((BasicHttpBinding)client.Endpoint.Binding).MaxBufferSize = 200000000;
((BasicHttpBinding)client.Endpoint.Binding).SendTimeout = System.TimeSpan.FromMinutes(3);
((BasicHttpBinding)client.Endpoint.Binding).MaxReceivedMessageSize = 200000000;
#endif
}
MyServiceClient.cs(从命令行使用 Svcutil.exe 生成)
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
#if !UNITY_EDITOR
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName = "IService1")]
public interface IService1
{
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IService1/getFolderNames", ReplyAction = "http://tempuri.org/IService1/getFolderNamesResponse")]
string[] getFolderNames();
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IService1/getFileNames", ReplyAction = "http://tempuri.org/IService1/getFileNamesResponse")]
string[] getFileNames(string fldrPath);
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IService1/getFileData", ReplyAction = "http://tempuri.org/IService1/getFileDataResponse")]
byte[] getFileData(string filePath);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface IService1Channel : IService1, System.ServiceModel.IClientChannel
{
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class Service1Client : System.ServiceModel.ClientBase<IService1>, IService1
{
public Service1Client()
{
}
public Service1Client(string endpointConfigurationName) :
base(endpointConfigurationName)
{
}
public Service1Client(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public Service1Client(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public Service1Client(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}
public string[] getFolderNames()
{
return base.Channel.getFolderNames();
}
public string[] getFileNames(string fldrPath)
{
return base.Channel.getFileNames(fldrPath);
}
public byte[] getFileData(string filePath)
{
return base.Channel.getFileData(filePath);
}
}
#endif
该服务运行良好,如下所示