简体   繁体   English

为什么我收到WCF错误?

[英]Why am I getting WCF error?

Am getting this error when I browse to a .svc page in IIS [ie. 当我浏览到IIS中的.svc页面时出现此错误[即。 http://localhost/PTSNew/PTNewService.svc ].Could you please advise on how to resolve this error?And also, is the url given in baseAddress attribute incorrect?Thanks. http://localhost/PTSNew/PTNewService.svc ]。请问您如何解决此错误?并且,baseAddress属性中给出的url是否不正确?谢谢。

* *

Service 'PTSNew.PriceTestingService' has zero application (non-infrastructure) endpoints. 服务'PTSNew.PriceTestingService'具有零应用程序(非基础结构)端点。 This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element. 这可能是因为没有为您的应用程序找到配置文件,或者因为在配置文件中找不到与服务名称匹配的服务元素,或者因为在service元素中没有定义端点。

* *

Heres my interface and app.config xml: 继承人我的界面和app.config xml:

namespace PTSNew 
{ 
    // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in App.config.

        public class PriceTestingService : IPriceTesting, IDisposable
}

namespace PTSNew 
{ 
    // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in App.config.

    [ServiceContract] 
    public interface IPriceTesting 
}

<system.serviceModel> 
    <bindings> 
      <basicHttpBinding> 
        <binding name="ProviderBinding" closeTimeout="00:01:00" openTimeout="00:01:00" 
                 receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" 
                 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
                 maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" 
                 messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> 
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
          <security mode="Transport"> 
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> 
            <message clientCredentialType="UserName" algorithmSuite="Default" /> 
          </security> 
        </binding> 
      </basicHttpBinding> 
      </bindings> 
    <services> 
      <service name="PTSNew.PriceTestingService" behaviorConfiguration="PTSNew.Service1Behavior"> 
        <host> 
          <baseAddresses> 
            <add baseAddress = "http://localhost:8731/Design_Time_Addresses/PTSNew/PriceTestingService/" /> 
          </baseAddresses> 
        </host> 
        <!-- Service Endpoints --> 
        <!-- Unless fully qualified, address is relative to base address supplied above --> 
        <endpoint address ="" binding="basicHttpBinding" contract="PTSNew.IPriceTesting"> 
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically. 
          --> 
          <identity> 
            <dns value="localhost"/> 
          </identity> 
        </endpoint> 
        <!-- Metadata Endpoints --> 
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> 
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment --> 
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
      </service> 
    </services> 
    <behaviors> 
      <serviceBehaviors> 
        <behavior name="PTSNew.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="False" /> 
        </behavior> 
      </serviceBehaviors> 
    </behaviors> 
  </system.serviceModel>

seems that you have forgotten to write contract attribute for the service element 好像你忘了为service元素写了contract属性

please go to the http://www.codeproject.com/KB/WCF/first_WCF_Service.aspx to see an example 请访问http://www.codeproject.com/KB/WCF/first_WCF_Service.aspx查看示例

I think you should place your configuration in web.config file instead of app.config if you are hosting it on IIS. 我认为如果您在IIS上托管它,您应该将配置放在web.config文件而不是app.config中。

And baseAddress is ignored when you are hosting WCF serwise on IIS. 当您在IIS上托管WCF时,将忽略baseAddress。 Base address is determined by web site and web application address where your WCF service is placed. 基址由放置WCF服务的网站和Web应用程序地址确定。

Your service contract ( IPriceTesting ) doesn't expose any methods. 您的服务合同( IPriceTesting )不公开任何方法。 You need to add methods to the interface and decorate them with the OperationContract attribute. 您需要向接口添加方法并使用OperationContract属性对其进行装饰。 After that, you need to implement those methods in your service class ( PriceTestingService ). 之后,您需要在服务类( PriceTestingService )中实现这些方法。

Example: 例:

[ServiceContract]
public interface IPriceTesting
{
    [OperationContract]
    decimal GetPrice(int productId);
}

And

public class PriceTestingService : IPriceTesting
{
    public decimal GetPrice(int productId)
    {
        //TODO: implement the method body
        throw new NotImplementedException();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM