2009-06-13 67 views
1

我的一个方法返回文件的byte []。所有其他方法返回字符串对象或自定义对象尝试使用返回文件的WCF服务时出错

我可以通过浏览器查看WSDL,因为我已经使用WCfExtras,我甚至可以查看文档。

在我的测试应用程序,C#web应用程序中,我添加了对我的svc的引用,托管在测试服务器上。我得到一个错误这样:

 The document was understood, but it could not be processed. 
    - The WSDL document contains links that could not be resolved. 
    - There was an error downloading ... 
    - Unable to connect to remote server 
    - No connection could be made because the target machine actively refused it 

    Content Type application/soap+xml; charset=utf-8 was not supported by service . The client and service bindings may be mismatched. 
    The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.. 
    If the service is defined in the current solution, try building the solution and adding the service reference again. 

这是我的app.config

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <connectionStrings> 
    <add name="TestApp.Properties.Settings.TestDBConnectionString" 
     connectionString="Data Source=192.168.2.130;Initial Catalog=TestDB;Persist Security Info=True;User ID=sa;Password=xerox" 
     providerName="System.Data.SqlClient" /> 
    </connectionStrings> 
    <system.web> 
    <compilation debug="true" /> 
    </system.web> 
    <!-- When deploying the service library project, the content of the config file must be added to the host's 
    app.config file. System.Configuration does not support config files for libraries. --> 
    <system.serviceModel> 
    <services> 
     <service behaviorConfiguration="TestApp.Service1Behavior" 
     name="TestApp.SearchService"> 
     <endpoint address="" behaviorConfiguration="Sample.WsdlSampleEndpointBehavior" 
      binding="basicHttpBinding" bindingConfiguration="WsHttpMtomBinding" contract="TestApp.ISearchService"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8731/TestApp/Service1/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="Sample.WsdlSampleEndpointBehavior"> 
      <wsdlExtensions location="http://localhost:8731/TestApp/Service1/"/> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior name="TestApp.Service1Behavior"> 
      <!-- 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="true" /> 
     </behavior> 

     </serviceBehaviors> 
    </behaviors> 
    <extensions> 
     <behaviorExtensions> 
     <!-- Declare that we have an extension called WSDL Extras--> 
     <add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> 
     </behaviorExtensions> 
    </extensions> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="WsHttpMtomBinding" messageEncoding="Mtom" transferMode="StreamedResponse" /> 
     </basicHttpBinding> 
    </bindings> 
    </system.serviceModel> 
</configuration> 

上我将如何解决这个任何想法?我应该有2个不同的绑定,一个用于返回非字节[]和Mtom返回字节[]的方法的方法?如果是这样,每个方法如何应用绑定?

试图与WcfTestClient.exe运行它,这是错误

rror: Cannot import wsdl:portTypeDetail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporterError: Schema with target namespace 'http://tempuri.org/' could not be found.XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='ISearchService']Error: Cannot import wsdl:bindingDetail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='ISearchService']XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='BasicHttpBinding_ISearchService']Error: Cannot import wsdl:portDetail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='BasicHttpBinding_ISearchService']XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:service[@name='SearchService']/wsdl:port[@name='BasicHttpBinding_ISearchService']Warning: No code was generated.If you were trying to generate a client, this could be because the metadata documents did not contain any valid contracts or servicesor because all contracts/services were discovered to exist in /reference assemblies. Verify that you passed all the metadata documents to the tool.Warning: If you would like to generate data contracts from schemas make sure to use the /dataContractOnly option. 

回答

0

在客户端应用程序,你必须将WCFExtras集的引用?该错误似乎是说,绑定不被识别,这是我认为,由于WCFExtras引入的扩展。尝试在服务器的配置文件中将相同的扩展部分添加到客户端的配置文件中。

+0

Jacob,我正在使用WCfTestClient.exe,VS2008的一部分尝试调用和使用我的服务。不知道我会如何在WcfTestClient.exe中添加该参考号 – user38230 2009-06-13 23:29:45

+0

我的意思是说,您可以将扩展名添加到您的客户端应用程序中。我想我假设你也在为你的Web服务编写一个客户端,而你的问题是你无法添加对它的引用。我对WcfTestClient.exe不是很熟悉。 如果您发布了正在生成的WSDL,我们可能可以更轻松地提供帮助。 – Jacob 2009-06-14 00:23:03

0

你的绑定是basicHttpBinding,但你的绑定配置是wsHttpMTOMBinding。

这看起来像一个不匹配,但它可能只是你给的东西的名字。

尝试打开W​​CF配置工具中的配置文件,这应该告诉你(拒绝打开文件),如果你的配置文件中存在不一致的地方。

希望这有助于

西拉

0

这不可能是一个真正的答案,但之后我从我的app.config文件删除WCfExtras引用和部署,事情似乎工作。

这就是我想实现,但已经放弃了暂时

WCF Extras

如果任何人有如何以及在什么我配置错了,请在此列建议的想法。

非常感谢

0

答案对我来说,能够使用WCF测试客户端是设置设置singleFile =“真”,在web配置是这样的。

<behavior name="Sample.WsdlSampleEndpointBehavior"> 
     <wsdlExtensions location="http://localhost:8731/TestApp/Service1/" singleFile="true" /> 
</behavior> 
1

我有同样的问题。我在IIS上的远程win2008服务器上托管wcf。已经为我工作的解决方案是在添加网站时设置主机名,并且在将所有其他数据设置为主机后不要留空白!