2012-04-27 64 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对于流的子集,一些额外的工作,但我不是很确定这一点。以上应该至少让你远离添加服务引用时看到的元数据错误。