现有的Asp.Net项目正在使用WCF WebService。 工作正常。
我决定将业务逻辑移到类库中。所以现在Class库使用WCF Web服务,而Asp.net应用程序没有引用它。
在Asp.net网络应用程序第一次调用类库(调试)时出现错误:
找不到引用合约'CouponParking.ICouponService'的默认端点元素 在ServiceModel客户端配置部分中。 这可能是因为找不到您的应用程序的配置文件, 或者因为在客户端元素中找不到与此合同匹配的端点元素。
我已经盯着类库app.config(当我第一次向WCF服务添加服务引用时由IDE创建),它看起来还不错。
假设需要改变,有人可以对它进行批评,并告诉我需要做什么。我对终点的理解还不成熟。
asp.net web.config确实有一个空的servicemodel部分。我认为这是正确的,因为服务引用已被删除。
类库app.config接着是WCF web.config,因此您可以看到另一端。
WCF还有一个额外的JSON端点,因为它也被Android设备使用。
App.Config中:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SoapEndPoint" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8707/CouponParking.svc/SOAP"
binding="basicHttpBinding" bindingConfiguration="SoapEndPoint"
contract="CouponParking.ICouponService" name="SoapEndPoint" />
</client>
</system.serviceModel>
</configuration>
Web.Config中:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxx" >
<section name="CouponParkingWCF.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttp" />
</basicHttpBinding>
<webHttpBinding>
<binding name="JsonBinding" />
</webHttpBinding>
</bindings>
<services>
<service name="CouponParkingWCF.CouponService">
<endpoint name ="SoapEndPoint"
address="SOAP"
binding="basicHttpBinding"
contract="CouponParkingWCF.ICouponService" />
<endpoint name="JSON"
address="REST" behaviorConfiguration="JsonBehavior" binding="webHttpBinding"
contract="CouponParkingWCF.ICouponService" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="JsonBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
<applicationSettings>
<CouponParkingWCF.Properties.Settings>
<setting name="ServerIp" serializeAs="String">
<value>192.168.0.224</value>
</setting>
<setting name="Database" serializeAs="String">
<value>WgtnTickTrakTest</value>
</setting>
</CouponParkingWCF.Properties.Settings>
</applicationSettings>
</configuration>
答案 0 :(得分:2)
类库使用其消费应用程序的配置文件 - 它们不使用自己的配置文件。因此,您需要将system.serviceModel
部分从库的app.congif移动到ASP.NET应用程序的web.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SoapEndPoint" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8707/CouponParking.svc/SOAP"
binding="basicHttpBinding"
bindingConfiguration="SoapEndPoint"
contract="CouponParking.ICouponService"
name="SoapEndPoint" />
</client>
</system.serviceModel>
现在,当您从ASP.NET应用程序调用类库时,它应该选择绑定和客户端端点。