【问题标题】:WCF service keeps tempUri namespaceWCF 服务保留 tempUri 命名空间
【发布时间】:2021-12-28 05:47:57
【问题描述】:

所以我需要为旧版客户端创建一些 WCF 服务。

问题是,在从 wdsl 文件生成合同后,我收到了反序列化错误,因为服务需要 http://tempuri.org/ 命名空间,即使合同中有正确的命名空间。

服务配置如下:

    <services>
        <service name="SystemNotificationHandling.Services.NotificationHandling">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="secureHttpBinding" contract="INotificationHandlingBinding"/>
        </service>
    </services>

    <bindings>
        <basicHttpBinding>
            <binding name="secureHttpBinding">
                <security mode="Transport">
                    <transport clientCredentialType="None"/>
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    
    <behaviors>
        <serviceBehaviors>
            <behavior>
                <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>

这是合同:

    [ServiceContract]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.8.3928.0")]
    [System.Web.Services.WebServiceBindingAttribute(Name="NotificationHandlingBinding", Namespace="http://xx.com/fake/1.0")]
    [System.Xml.Serialization.XmlIncludeAttribute(typeof(ResponseMessage))]
    [System.Xml.Serialization.XmlIncludeAttribute(typeof(Header))]
    [System.Xml.Serialization.XmlIncludeAttribute(typeof(NotificationRequestMessage))]
    public interface INotificationHandlingBinding 
    {
        
        [OperationContract]
        [System.Web.Services.WebMethodAttribute()]
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://xx.com/fake/1.0/notifyEvent", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
        [return: System.Xml.Serialization.XmlElementAttribute("NotifyEventResponse", Namespace="http://xx.com/fake/1.0")]
         NotifyEventResponse notifyEvent([System.Xml.Serialization.XmlElementAttribute(Namespace="http://xx.com/fake/1.0")] NotifyEventRequest NotifyEventRequest);
        
    }

感谢您的帮助。

【问题讨论】:

  • 一般来说,您需要在三个地方显式设置命名空间以摆脱 tempuri.org 的默认值: 1.ServiceContract 属性(在合同上) 2.ServiceBehavior 属性(在实现上) 3.bindingNamespace 放在配置文件中相关服务的 元素上。 c-sharpcorner.com/forums/get-rid-of-tempuri-in-wsdl

标签: c# wcf


【解决方案1】:

事实证明,合同生成是错误的。我们再次通过 svcutil 生成合约,这次它为 OperationContract 属性和 ServiceContract 属性添加了命名空间。

谢谢兰煌,你的评论给我指明了正确的方向。

【讨论】:

    猜你喜欢
    • 2015-04-27
    • 1970-01-01
    • 1970-01-01
    • 2019-04-13
    • 2010-11-15
    • 2016-06-14
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    相关资源
    最近更新 更多