2009-06-13 60 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。已經爲我工作的解決方案是在添加網站時設置主機名,並且在將所有其他數據設置爲主機後不要留空白!

相關問題