2012-04-27 42 views
0

我從控制檯應用程序引用WCF服務時收到元數據錯誤。 「從地址下載元數據時出錯」。這是我的服務代碼。我感謝任何幫助。wcf元數據錯誤

namespace WcfService1 
{ 
    public class Service1 : IService1 
    { 
     public void test(string parm1, long parm2, Stream parm3) 
     { 

      string folder1 = @"C:\TEST"; 
      string fileName = Path.Combine(folder1, parm1); 

      using (FileStream target = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) 
      { 

        const int bufferLen = 65536; 
        byte[] buffer = new byte[bufferLen]; 
        int count = 0; 
        while ((count = parm3.Read(buffer, 0, bufferLen)) > 0) 
        { 
         target.Write(buffer, 0, count); 
        } 
      } 

     } 
    } 
} 

    namespace WcfService1 
    { 

     [ServiceContract] 
     public interface IService1 
     { 
      [OperationContract] 
      void test(string parm1, long parm2, Stream parm3); 
     } 
    } 

下面是配置:

<?xml version="1.0"?> 
<configuration> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

</configuration> 
+0

marc_s:請參閱我的配置。 – nav100 2012-04-27 16:40:22

回答

0

最有可能的,這是由於你採取System.IO.Stream作爲參數來測試。根據我的經驗(有人可能會在這裏糾正我),您有兩種選擇:

  1. 將請求包裝在請求對象中(請參見下文)。
  2. 刪除param1和param2,只使用Stream-param。

服務接口:

[ServiceContract] 
public interface IService1 
{ 

     [OperationContract] 
     void test(Request request); 
} 

DataContract:

namespace WcfService1 
{ 
    [DataContract] 
    public class Request 
    { 
     [DataMember] 
     public string Param1 { get; set; } 
     [DataMember] 
     public long Param2 { get; set; } 
     [DataMember] 
     public Stream Param3 { get; set; } 
    } 
} 

您可能需要使用[KnownType對於流的子集,一些額外的工作,但我不是很確定這一點。以上應該至少讓你遠離添加服務引用時看到的元數據錯誤。