对于WCF的几个问题
我想请问几个WCF的问题:
1、如果Service部分没有暴露metadata endpoints,Client部分是否可以使用WsdlImporter以及ChannelFactory动态调用Service?比如,如果Client使用下面的代码去动态调用一个File Download Service,那么在Service部分是否需要暴露metadata endpoint?
2、如果上面的回答是“必须暴露”,那么,如果我希望我的Service始终能够被动态调用,那暴露这个metadata endpoint是否会有安全威胁?如何解决这个矛盾?
3、Binding的设置问题。
比如,我的服务端是采用代码动态配置Service的,代码如下:
而客户端是用的第一个问题中的代码。其实事实上Service部分暴露了一个BasicHttpBinding的endpoint,并且设置了这个binding的MaxReceivedMessageSize以及TransferMode,但是我在Client端调试的时候,发现importer.ImportAllEndpoints调用所获得的binding虽然也是BasicHttpBinding,但是上述属性的设置值都遗失了(变成了默认值),这是什么原因呢?有没有办法解决?
希望高人出手相救!
1、如果Service部分没有暴露metadata endpoints,Client部分是否可以使用WsdlImporter以及ChannelFactory动态调用Service?比如,如果Client使用下面的代码去动态调用一个File Download Service,那么在Service部分是否需要暴露metadata endpoint?
static void Main(string[] args)
{
EndpointAddress mexAddress = new EndpointAddress("http://localhost:8889/FileTransfer/mex");
MetadataExchangeClient mexClient = new MetadataExchangeClient(mexAddress);
MetadataSet metadataSet = mexClient.GetMetadata();
WsdlImporter importer = new WsdlImporter(metadataSet);
ServiceEndpointCollection endpoints = importer.ImportAllEndpoints();
ChannelFactory<IFileDownloader> factory = new ChannelFactory<IFileDownloader>(
endpoints[0].Binding, endpoints[0].Address);
IFileDownloader downloader = factory.CreateChannel();
DownloadRequest request = new DownloadRequest("C:\\VIRTPART.DAT");
DownloadResponse response = downloader.Download(request);
Console.WriteLine(response.FileName);
Console.WriteLine(response.Size);
}
2、如果上面的回答是“必须暴露”,那么,如果我希望我的Service始终能够被动态调用,那暴露这个metadata endpoint是否会有安全威胁?如何解决这个矛盾?
3、Binding的设置问题。
比如,我的服务端是采用代码动态配置Service的,代码如下:
static void Main(string[] args)
{
ContractDescription cd = ContractDescription.GetContract(typeof(IFileDownloader));
BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
basicHttpBinding.MaxReceivedMessageSize = 10067108864;
basicHttpBinding.TransferMode = TransferMode.Streamed;
basicHttpBinding.MessageEncoding = WSMessageEncoding.Mtom;
//WSHttpBinding basicHttpBinding = new WSHttpBinding();
ServiceEndpoint endpoint = new ServiceEndpoint(
cd,
basicHttpBinding,
new EndpointAddress("http://localhost:8889/FileTransfer/"));
ContractDescription mexCd = ContractDescription.GetContract(typeof(IMetadataExchange));
ServiceEndpoint mexEndpoint = new ServiceEndpoint(
mexCd,
MetadataExchangeBindings.CreateMexHttpBinding(),
new EndpointAddress("http://localhost:8889/FileTransfer/mex"));
System.ServiceModel.ServiceHost host = new System.ServiceModel.ServiceHost(typeof(FileTransferImpl));
host.Opened += (a, b) => Console.WriteLine("Service Opened.");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.HttpGetUrl = new Uri("http://localhost:8889/FileTransfer/mex");
host.Description.Behaviors.Add(smb);
host.AddServiceEndpoint(endpoint.Contract.ContractType, endpoint.Binding, endpoint.Address.ToString());
host.AddServiceEndpoint(mexEndpoint.Contract.ContractType, mexEndpoint.Binding, mexEndpoint.Address.ToString());
host.Open();
foreach (ServiceEndpoint ep in host.Description.Endpoints)
{
Console.WriteLine(ep.Address.ToString());
}
Console.ReadLine();
}
而客户端是用的第一个问题中的代码。其实事实上Service部分暴露了一个BasicHttpBinding的endpoint,并且设置了这个binding的MaxReceivedMessageSize以及TransferMode,但是我在Client端调试的时候,发现importer.ImportAllEndpoints调用所获得的binding虽然也是BasicHttpBinding,但是上述属性的设置值都遗失了(变成了默认值),这是什么原因呢?有没有办法解决?
希望高人出手相救!
...全文
相关推荐
C#中使用WCF一些常见问题及解决方案
近在学习WCF,在这过程当中我遇到了很多的问题,简单说说我遇到的问题已经可能有效的解决方案。 1.在C#中,同一个解决方案下无法引用别的项目,引用之后会有一个警告,查看属性找不到引用的路径,这种情况大部分都是由于两个项目的版本不一致所导致的。 2.在C#中,重新引用服务或者是更新服务引用的时候,如果出现无法生成解决方案的情况,可以试试右击"配置服务引用",在服务引用设置对话框中,将“重新使用引用的程序 集中的类型”这个勾取消,这样能安全的重新引用服务了。 3.在C#中,如果客户端需要使用服务端的实体,则可以在添加服务引用的时候设置"选择重新使用所引用的指定程序集中的类
WCFMessenger,一个wcf的聊天程序
WCFMessenger,一个wcf的聊天程序 讨论:http://bbs.csdn.net/topics/390435061
在IIS上部署Silverlight+WCF项目教程
在IIS上部署Silverlight+WCF项目教程。
Android访问WCF服务源码(WCF服务端)
http://blog.csdn.net/btyh17mxy/article/details/7993111的源码
WCF PDA开发资源 WCF Guidance For Mobile Developers
英文版,WCF Guidance For Mobile Developers 写的很好,对Windows Mobile. WindowsCE的WCF开发很有帮助! 资源包括pdf文档和代码!


