如何在真实环境中测试wcf

时间:2012-03-07 11:37:33

标签: asp.net wcf web-services

我使用wcf进行了一项服务我通过向asp.net类型的客户端制作项目来测试它,它完美无缺。我在IIS上托管服务和客户端我想在不打开visual studio的情况下运行。当我关闭visual studio并将我的客户端项目的URL放入时,它会给我这个错误

无法在ServiceModel客户端配置部分中找到引用合同“ServiceReference1.IService1”的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。

描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

  

异常详细信息:System.InvalidOperationException:找不到   引用合同的默认端点元素   ServiceModel客户端配置中的“ServiceReference1.IService1”   部分。这可能是因为找不到配置文件   您的应用程序,或者没有匹配此的端点元素   合同可以在客户要素中找到。

     

来源错误:

     

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

     

源文件:C:\ Users \ KHALED \ documents \ visual studio   2010 \ Projects \ WcfServicefiles \ WebApplication2 \ Default.aspx.cs行:   29个
  这是服务的web.config

  <?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>

这是客户端的web.config

<?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>

2 个答案:

答案 0 :(得分:0)

首先尝试在控制台应用中托管您的服务可能是个好主意。肖恩是对的,看看你的配置会很有帮助。

在visual studio中运行服务时,会自动为您托管该服务。在visual studio外部进行测试时:运行服务主机,打开浏览器并输入主机的BASE地址。如果meata数据可用,您应该会看到一个包含wsdl定义链接的页面。

基本地址可能看起来像http://192.168.89.73:8080/base,包含您机器的IP地址,端口号....

答案 1 :(得分:0)

VS附带的

WCFTestClient用于测试WCF。