2012-03-07 23 views
0

我已經使用wcf做了一個服務,我測試了一個項目到一個類型爲asp.net的客戶端,它的工作原理是完美的。我在IIS上託管了服務和客戶端,運行時不打開視覺工作室。當我關閉視覺工作室,並把我的客戶端項目的URL它給了我這個錯誤如何在真實環境中測試wcf

無法找到在ServiceModel客戶端配置部分中引用合同'ServiceReference1.IService1'的默認端點元素。這可能是因爲沒有找到適用於您的應用程序的配置文件,或者因爲在客戶端元素中找不到匹配此合同的端點元素。

描述:執行當前Web請求期間發生未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。

Exception Details: System.InvalidOperationException: Could not find default endpoint element that references contract 'ServiceReference1.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

Source Error:

Line 27: Line 28: System.IO.FileInfo fileinfo = new System.IO.FileInfo(FileUpload1.PostedFile.FileName); Line 29:
ServiceReference1.IService1 clientupload = new ServiceReference1.Service1Client(); Line 30:
ServiceReference1.RemoteFileInfo uploadRequestInfo = new ServiceReference1.RemoteFileInfo(); Line 31: Link = FileUpload1.PostedFile.FileName;

Source File: C:\Users\KHALED\documents\visual studio 2010\Projects\WcfServicefiles\WebApplication2\Default.aspx.cs Line: 29
here's the web.config of the service

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

    <system.web> 
    <compilation debug="true" targetFramework="4.0"/> 
    <httpRuntime maxRequestLength="2097151" 
    useFullyQualifiedRedirectUrl="true" 
    executionTimeout="14400"/> 
    </system.web> 
    <system.serviceModel> 
    <client /> 
    <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="true"/> 
      <dataContractSerializer maxItemsInObjectGraph="6553600"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="Service1" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" 
      transferMode="Streamed"> 
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
      maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
      <security mode="None"> 
      <transport clientCredentialType="Ntlm" /> 
      </security> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <services> 
     <service name="WcfServicefinal.Service1" > 
     <endpoint address="" binding="basicHttpBinding" 
        bindingConfiguration="Service1" 
        contract="WcfServicefinal.IService1" > 

     </endpoint> 
     </service> 

    </services> 

     <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

</configuration> 

這是客戶端

<?xml version="1.0"?> 

<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    http://go.microsoft.com/fwlink/?LinkId=169433 
    --> 

<configuration> 
    <connectionStrings> 
    <add name="ApplicationServices" 
     connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" 
     providerName="System.Data.SqlClient" /> 
    </connectionStrings> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 

    <authentication mode="Forms"> 
     <forms loginUrl="~/Account/Login.aspx" timeout="2880" /> 
    </authentication> 

    <membership> 
     <providers> 
     <clear/> 
     <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" 
      enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" 
      maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" 
      applicationName="/" /> 
     </providers> 
    </membership> 

    <profile> 
     <providers> 
     <clear/> 
     <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/> 
     </providers> 
    </profile> 

    <roleManager enabled="false"> 
     <providers> 
     <clear/> 
     <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" /> 
     <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" /> 
     </providers> 
    </roleManager> 

    </system.web> 

    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00" 
      openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" 
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 
      messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed" 
      useDefaultWebProxy="true"> 
      <readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647" 
      maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
      <security mode="None"> 
      <transport clientCredentialType="None" proxyCredentialType="None" 
       realm="" /> 
      <message clientCredentialType="UserName" algorithmSuite="Default" /> 
      </security> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost/WcfServicefinal/Service1.svc" 
     binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" 
     contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" /> 
    </client> 
    </system.serviceModel> 
</configuration> 
+0

是的,我可以導航到服務沒有運行VS – 2012-03-07 16:38:49

+0

我已經添加了服務和客戶端的web.config – 2012-03-07 16:49:28

回答

0

它可能是一個好主意,嘗試在一個控制檯應用程序託管服務作爲第一個去的web.config文件。肖恩是對的,這將有助於看到你的配置。

在Visual Studio中運行服務時,該服務會自動爲您託管。在Visual Studio之外測試時:運行您的服務主機,打開瀏覽器並輸入主機的BASE地址。如果meata數據可用,您應該會看到一個帶有wsdl定義鏈接的頁面。

基址可能看起來像http://192.168.89.73:8080/base與你的機器,端口號的IP地址....