【问题标题】:Eliminating tempuri from a WCF Web Service which has FaultException从具有 FaultException 的 WCF Web 服务中消除 tempuri
【发布时间】:2013-02-25 16:57:22
【问题描述】:

背景:

我最近添加了对 Web 服务的用户请求的内部身份验证,如果身份验证失败,则会引发自定义 FaultException。

FaultException 自定义类型已被标记:

[DataContract(Namespace = ConstantConfig.ServiceNamespace, Name = "AuthenticationError")]
public class AuthenticationError

服务接口方法已被标记:

[OperationContract]
[FaultContract(typeof(AuthenticationError), Namespace = ConstantConfig.ServiceNamespace)]
ClientReport GetClientReport(DateTime from, DateTime to);

接口本身已被标记:

[ServiceContract(Namespace = ConstantConfig.ServiceNamespace)]
public interface IClientReportService

接口的实现已标注:

[ServiceBehavior(Namespace = ConstantConfig.ServiceNamespace)]
public class ClientReportService : IClientReportService

web.config 和 app.config 都指向复制/粘贴的服务命名空间。

然而,尽管如此,我仍然会生成 tempuri.wsdl。以下是 wsdl 的代表性摘录:

主要:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://webservice.company.com/ClientReportService" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:i0="http://tempuri.org/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ClientReportService" targetNamespace="http://webservice.company.com/ClientReportService" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:import namespace="http://tempuri.org/" location="http://localhost:4319/ClientReportService.svc?wsdl=wsdl0" />
<wsdl:types>
<xsd:schema targetNamespace="http://webservice.company.com/ClientReportService/Imports">
    <xsd:import schemaLocation="http://localhost:4319/ClientReportService.svc?xsd=xsd0" namespace="http://webservice.company.com/ClientReportService" />
    <xsd:import schemaLocation="http://localhost:4319/ClientReportService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
</xsd:schema>
</wsdl:types>

天妇罗:

<wsdl:operation name="GetClientReport">
  <soap:operation soapAction="http://webservice.company.com/ClientReportService/IClientReportService/GetClientReport" style="document" />
  <wsdl:input>
    <soap:body use="literal" />
  </wsdl:input>
  <wsdl:output>
    <soap:body use="literal" />
  </wsdl:output>
  <wsdl:fault name="AuthenticationErrorFault">
    <soap:fault use="literal" name="AuthenticationErrorFault" namespace="" />
  </wsdl:fault>
</wsdl:operation>

我猜有些东西我没有标记或标记不正确,但不知所措。

有什么建议吗?

【问题讨论】:

  • 我目前在想,因为这个元素上的命名空间是空的: 当自动生成 WSDL 时,整个块被放入 tempuri。任何人都知道如何确保命名空间被填充?

标签: c# wcf .net-4.0 wsdl


【解决方案1】:

试试这个

<endpoint address=""
                          binding="basicHttpBinding"
                          bindingNamespace="http://my.namespace.com"
                          contract=""/>
            </service>

【讨论】:

  • 感谢您的回复,但我假设您的端点是这样的:webservice.company.com/ClientReportService"> 我们已经标记了这个。除非我需要一个空白端点?
【解决方案2】:

事实证明这个错误完全是我的。

在网络配置中,服务名称与实际服务上的服务名称不匹配。

实际服务(在 .svc 文件的标记内):

Service="Company.Client.Framework.ReportService.ClientReportService"

损坏的网络配置

<service name="Company.Client.ReportService.ReportService">

更正的网络配置:

<service name="Company.Client.ReportService.ClientReportService">

在我更正此问题并重新生成 WSDL 后,tempuri 消失了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-13
    • 1970-01-01
    相关资源
    最近更新 更多