我需要从便携式库访问WCF服务,但我遇到了异常。
我使用c#创建了一个NetHttpBinding:
var serviceHost = new ServiceHost(classType, new Uri("http://localhost:23166/EbmsServices/DataAccess/E21/NET"));
serviceHost.AddServiceEndpoint(endpointInterface, new NetHttpBinding(), "");
var smb = new ServiceMetadataBehavior() { HttpGetEnabled = true };
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
serviceHost.Description.Behaviors.Add(smb);
serviceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
// Open the ServiceHostBase to create listeners and start listening for messages.
serviceHost.Open();
在客户端可移植库中,我使用Visual Studio添加了服务引用。
以下是便携式库中的代码:
Service = new DataAccessClient(new NetHttpBinding() { SendTimeout = SendTimeout, ReceiveTimeout = ReceiveTimeout }, new EndpointAddress(ServiceUrl));
Service.ValidateLoginCompleted += Service_ValidateLoginCompleted;
Service.ValidateLoginAsync(new ValidateLoginRequest(Guid.NewGuid(), username, password));
服务启动很好,我可以从非可移植的库中访问它,但是当我尝试使用可移植库时,我得到了这个例外:
An exception of type 'System.ServiceModel.EndpointNotFoundException' occurred in System.ServiceModel.Internals.dll but was not handled in user code
Additional information: There was no endpoint listening at http://localhost:23166/EbmsServices/DataAccess/E21/NET that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
内部例外: 无法连接到远程服务器
内在的例外: 无法建立连接,因为目标计算机主动拒绝它[:: 1]:23166
在便携式库中,我需要做些什么才能使其工作?
为了记录,可移植库的目标是.Net Framework 4.5.1和Windows 8.1。此外,这在Windows 8.1应用程序中也可以使用。
谢谢!