当我浏览到IIS中的.svc页面时出现此错误 [即。 http://localhost/PTSNew/PTNewService.svc ]。请问您如何解决此错误?并且,baseAddress属性中给出的url是否不正确?谢谢。
*
服务'PTSNew.PriceTestingService'没有应用程序 (非基础设施)端点。这可能是因为没有配置 找到了您的应用程序的文件,或者因为没有服务元素 匹配服务名称可以在配置文件中找到,或者 因为没有在服务元素中定义端点。
*
继承我的界面和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>
答案 0 :(得分:2)
您似乎忘记为服务元素编写合同属性
请转到http://www.codeproject.com/KB/WCF/first_WCF_Service.aspx查看示例
答案 1 :(得分:0)
如果您在IIS上托管它,我认为您应该将配置放在web.config文件而不是app.config。
当您在IIS上托管WCF时,将忽略baseAddress。基地址由放置WCF服务的网站和Web应用程序地址确定。
答案 2 :(得分:0)
您的服务合同(IPriceTesting
)不公开任何方法。您需要向接口添加方法并使用OperationContract
属性对其进行装饰。之后,您需要在服务类(PriceTestingService
)中实现这些方法。
示例:
[ServiceContract]
public interface IPriceTesting
{
[OperationContract]
decimal GetPrice(int productId);
}
和
public class PriceTestingService : IPriceTesting
{
public decimal GetPrice(int productId)
{
//TODO: implement the method body
throw new NotImplementedException();
}
}