Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.Net类库项目访问WCF_Asp.net_Wcf_Wcf Binding - Fatal编程技术网

ASP.Net类库项目访问WCF

ASP.Net类库项目访问WCF,asp.net,wcf,wcf-binding,Asp.net,Wcf,Wcf Binding,现有Asp.Net项目正在使用WCF Web服务。 工作正常 我决定将业务逻辑移到类库中。因此,现在类库使用WCF web服务,而Asp.net应用程序没有对它的引用 Asp.net web应用程序(调试)第一次调用类库时,我收到一个错误: 找不到引用约定“CouponParking.ICouponService”的默认终结点元素 在ServiceModel客户端配置部分中。 这可能是因为找不到应用程序的配置文件, 或者因为在客户端元素中找不到与此约定匹配的端点元素 我已经开始关注类库app.c

现有Asp.Net项目正在使用WCF Web服务。 工作正常

我决定将业务逻辑移到类库中。因此,现在类库使用WCF web服务,而Asp.net应用程序没有对它的引用

Asp.net web应用程序(调试)第一次调用类库时,我收到一个错误:

找不到引用约定“CouponParking.ICouponService”的默认终结点元素 在ServiceModel客户端配置部分中。 这可能是因为找不到应用程序的配置文件, 或者因为在客户端元素中找不到与此约定匹配的端点元素

我已经开始关注类库app.config(它是在我第一次向WCF服务添加服务引用时由IDE创建的),在我看来还可以

假设它需要改变,请有人对它投以批判的眼光,告诉我需要做什么。我对端点的理解是初步的

asp.net web.config的servicemodel部分为空。我认为这是正确的,因为服务引用已被删除

类库app.config随后是wcfweb.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>
<?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>

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

192.168.0.224
WgtnTickTrakTest

类库使用其消费应用程序的配置文件-它们不使用自己的配置文件。因此,您需要将
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应用程序调用类库时,它应该会选择绑定和客户端端点。

谢谢,现在有意义了。在Asp.net仍有服务引用时完成初始测试。最后才把它拿走。这真的节省了我的时间,谢谢