遇到 Web Service 报错:无法从命名空间“http://tempuri.org/”导入绑定“”,当我们开发Web Service时一般命名空间就是:http://tempuri.org/。
英文报的错如下:The service operation '' that belongs to the contract with the '' name and the 'http://tempuri.org/' namespace does not allow impersonation
遇到这个错误最典型的场景是可能你在使用动动态调用的方法解析wdls文档,然后根据解析动态调用方法,此web 服务的接口描述文档不符合soap1.1或者soap1.2的规范会导致这个错误。
这里有几个要点先奉上:
(1)在wcf服务中的绑定要使用BasicHttpBinding,其它的绑定都不是对soap设计的。
(2)检查你的wcf地址在浏览器访问一下试一试,是不是有误。
我的使用场景是通过C#代码调用服务的wsdl的服务描述信息,来生成代码。遇到如下消息:System.InvalidOperationException:“无法从命名空间“http://tempuri.org/”导入绑定“BasicHttpBinding_IWxTest”。
关键代码如下:
ServiceDescriptionImporter descriptionImporter = new ServiceDescriptionImporter()
{
ProtocolName = "Soap",
Style = ServiceDescriptionImportStyle.Client,
CodeGenerationOptions =
CodeGenerationOptions.GenerateProperties | CodeGenerationOptions.GenerateNewAsync
};
descriptionImporter.AddServiceDescription(description, string.Empty, string.Empty);
CodeNamespace nameSpace = new CodeNamespace();//_serviceNamespace
CodeCompileUnit compile = new CodeCompileUnit();
compile.Namespaces.Add(nameSpace);
descriptionImporter.Import(nameSpace, compile);
那这个错误怎么解决呢?提供一个比较不好的解决办法,把wcf 换成asmx传统的服务。这个显然不是我们能控制的,也不是我们想要的。
下面提供一个超级简单的办法,请点击捐赠按钮来查看更多内容!
💰 此内容为付费阅读 请先登录