2013-02-25 24 views
1

背景:從具有的FaultException一個WCF Web服務消除tempuri

我最近添加了用戶請求的內部驗證的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一個reprsentative摘錄:

主營:

<?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> 

Tempuri:

<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> 

我猜有什麼,我還沒有打上了或錯誤地標記,但我無法找到它。

有什麼建議嗎?

+0

我現在想,因爲該元素的名稱空間是空的: <肥皂:故障使用=「文本」名稱=「AuthenticationErrorFault」命名空間=「」 /> 當WSDL自動生成時,整個塊被放入tempuri。任何人都知道如何確保名稱空間已填充? – Mohammed 2013-02-26 10:31:03

回答

3

試試這個

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

謝謝你的迴應,但我通過終點假設你的意思是: <端點名稱=「BasicEndpoint」 地址=「」 綁定=「basicHttpBinding的」 bindingConfiguration =「BasicBinding」 合同=「公司.client.ClientReportService.IClientReportService「 bindingNamespace =」http://webservice.company.com/ClientReportService「> 我們已經有了這個標記。除非我需要一個空白的端點? – Mohammed 2013-02-25 17:05:57

2

事實證明錯誤完全是我的。

在Web配置中,服務名稱與實際服務上的服務名稱不匹配。

實際服務(標記爲.svc文件內):

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

破碎Web配置

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

糾正後的Web配置:

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

我糾正了這個之後重新生成了WSDL,tempuri消失了。