IWsdlExportExtension不更新服务wsdl [英] IWsdlExportExtension does not update a service wsdl

查看:52
本文介绍了IWsdlExportExtension不更新服务wsdl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试替换服务地址(http -> https).为了实现这一点,我使用了自己的行为,该行为实现了IWsdlExportExtension,IEndpointBehavior 和IServiceBehavior.在ExportEndpoint方法中,将处理替换.在调试器中,我可以看到一切正常(替换了字符串).

公共无效ExportEndpoint(WsdlExporter导出器,WsdlEndpointConversionContext上下文)
    {
        EndpointAddress endpointAddress = context.Endpoint.Address;
        字符串newAbsoluteUri = endpointAddress.Uri.AbsoluteUri.Replace("http://","https://");
        Uri newUri =新Uri(newAbsoluteUri);
        context.Endpoint.Address =新的EndpointAddress(newUri,endpointAddress.Identity,endpointAddress.Headers,endpointAddress.GetReaderAtMetadata(),endpointAddress.GetReaderAtExtensions());
    } 

不幸的是,当我在浏览器中打开服务并进入wsdl文件时,我看到了什么都没有被取代.我必须注意到web.config似乎已配置 好吧.有一个扩展名,用于正确的服务行为(由我的服务使用).怎么了?我忘了什么吗?

解决方案

fake_user,

您能否与我们分享为什么要将http更改为https?据我了解,如果在不配置传输安全性的情况下使用http托管服务,然后通过https请求,则会出现不匹配错误.

我用您的方式进行了测试,我可以重现您的问题.为了将http更改为https,我认为您可以实现IServiceBehavior.这是一个简单的代码:

//定义自定义服务行为
   公共类ChangeHttps:IServiceBehavior
    {
        公共无效AddBindingParameters(ServiceDescription serviceDescription,ServiceHostBase serviceHostBase,Collection< ServiceEndpoint>端点,BindingParameterCollection bindingParameters)
        {
            foreach(端点中的ServiceEndpoint端点)
            {
                字符串newAbsoluteUri = endpoint.Address.Uri.AbsoluteUri.Replace("http://","https://");
                Uri newUri =新Uri(newAbsoluteUri);
                endpoint.Address =新的EndpointAddress(newAbsoluteUri);
            }
        }

        公共无效ApplyDispatchBehavior(ServiceDescription serviceDescription,ServiceHostBase serviceHostBase)
        {
            
        }

        公共无效Validate(ServiceDescription serviceDescription,ServiceHostBase serviceHostBase)
        {
            
        }
    }
//托管wcf服务
字符串baseAddress ="http://localhost:8000/Service";
            Console.WriteLine(baseAddress);
            ServiceHost主机=新的ServiceHost(typeof(CalculatorService),新的Uri(baseAddress));
            ServiceEndpoint端点= host.AddServiceEndpoint(typeof(ICalculator),new WSHttpBinding(),");
            host.Description.Behaviors.Add(new ChangeHttps {});
            host.Description.Behaviors.Add(new ServiceMetadataBehavior {HttpGetEnabled = true});
            host.Open();
            Console.WriteLine(主机已打开"); 

有关更多信息,建议您参考以下链接:

#动态更新WSDL元数据中的WCF端点地址
https://pieterderycke.wordpress.com /2011/06/03/dynamically-updating-wcf-endpoint-addresses-wsdl-meta-data/

请注意,更改服务地址后,恐怕要在客户和服务之间建立社区并不容易.

最好的问候,

爱德华

注意:此回复包含对第三方万维网站点的引用. Microsoft为方便您而提供此信息.
Microsoft不控制这些站点,也没有测试在这些站点上找到的任何软件或信息;
因此,Microsoft无法对在此找到的任何软件或信息的质量,安全性或适用性做出任何陈述.
使用Internet上发现的任何软件都存在固有的危险,Microsoft提醒您在从Internet上检索任何软件之前,请确保您完全了解风险.


I am trying to replace the service address (http -> https). To achieve that I am using own behavior which implements IWsdlExportExtension, IEndpointBehavior and IServiceBehavior. In ExportEndpoint method replacing is processed. In debugger I can see that everything works good (string is replaced).

public void ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)
    {            
        EndpointAddress endpointAddress = context.Endpoint.Address;
        string newAbsoluteUri = endpointAddress.Uri.AbsoluteUri.Replace("http://", "https://");
        Uri newUri = new Uri(newAbsoluteUri);
        context.Endpoint.Address = new EndpointAddress(newUri, endpointAddress.Identity, endpointAddress.Headers, endpointAddress.GetReaderAtMetadata(), endpointAddress.GetReaderAtExtensions());
    }

Unfortunatelly, when I open the service in browser and go into wsdl file I see that nothing was replaced. I must notice that web.config seems to be configured well. There is an extension which is used in proper service behavior (used by my service). What is wrong? Did I forget about something?

解决方案

Hi fake_user,

Could you share us why you want to change the http to https? As my understanding, if you host service with http without configuring transport security, and then you request by https, you will get mismatch error.

I made a test with your way, and I could reproduce your issue. For changing the http to https, I think you could implement IServiceBehavior. Here is a simple code:

//define custom service behavior 
   public class ChangeHttps : IServiceBehavior
    {
        public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
        {
            foreach (ServiceEndpoint endpoint in endpoints)
            {
                string newAbsoluteUri = endpoint.Address.Uri.AbsoluteUri.Replace("http://", "https://");
                Uri newUri = new Uri(newAbsoluteUri);
                endpoint.Address = new EndpointAddress(newAbsoluteUri);                
            }
        }

        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            
        }

        public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            
        }
    }
//host wcf service
string baseAddress = "http://localhost:8000/Service";
            Console.WriteLine(baseAddress);
            ServiceHost host = new ServiceHost(typeof(CalculatorService), new Uri(baseAddress));
            ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding()  , "");
            host.Description.Behaviors.Add(new ChangeHttps {  });
            host.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true });
            host.Open();
            Console.WriteLine("Host opened");

For more information, I suggest you refer the link below:

# Dynamically updating WCF endpoint addresses in WSDL meta data
https://pieterderycke.wordpress.com/2011/06/03/dynamically-updating-wcf-endpoint-addresses-in-wsdl-meta-data/

Note, after changing service address, I am afraid it is not easy to community between client and service.

Best Regards,

Edward

Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.
Microsoft does not control these sites and has not tested any software or information found on these sites;
Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


这篇关于IWsdlExportExtension不更新服务wsdl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆