0

我已经使用 ASP.NET 4 创建了一个 WCF 服务,并试图在我自己的 Web 应用程序项目中连接到它,这给了我“找不到默认端点元素”错误。

这个类似问题的答案似乎都对我没有帮助,因为它们似乎都在处理一个引用该服务并且缺少配置文件的外部项目。

该服务在直接使用其方法时起作用(例如:JS 调用)。

有任何想法吗?请在下面查看我的 serviceModel 部分:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="metadataBehavior">
        <serviceMetadata httpGetEnabled = "true"/>
      </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
      <behavior name="webHttpBehavior">
        <webHttp />
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <bindings>
    <webHttpBinding>
      <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
    </webHttpBinding>
  </bindings>
  <services>
    <service name="MapiWebService.CrmService" behaviorConfiguration="metadataBehavior">
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:64049/Service/CrmService.svc"/>
        </baseAddresses>
      </host>
      <endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="MapiWebService.CrmService" behaviorConfiguration="webHttpBehavior" />
      <endpoint address="http://localhost:64049/Service/CrmService.svc/mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
  </services>
</system.serviceModel>

这是我的服务课程的开场白:

namespace MapiWebService
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class CrmService : PortalService
    {
        [OperationContract]
        [WebGet(ResponseFormat = WebMessageFormat.Json)]
        public string Authenticate(string username, string password)
4

2 回答 2

0

您必须为客户端应用程序的服务模型和 WCF 服务模型编写代码。(在 web 配置文件中)

对于客户端应用程序 web 配置..

      <system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
  multipleSiteBindingsEnabled="true" />
<services>
  <service name="UserSiteApp.AjxWcfService" >
    <endpoint contract="UserSiteApp.AjxWcfService" binding="webHttpBinding" address=""  behaviorConfiguration="UserSiteApp.MyServiceTypeBehaviors" />
  </service>
</services>
<bindings>
  <basicHttpBinding>
    <binding name="Binding1" closeTimeout="04:10:00" openTimeout="04:10:00" receiveTimeout="04:10:00" sendTimeout="04:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="1073741824" maxBufferPoolSize="1073741824" maxReceivedMessageSize="1073741824" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <!--<compressionMessageEncoding innerMessageEncoding="binaryMessageEncoding" />-->
      <readerQuotas maxDepth="1073741824" maxStringContentLength="1073741824" maxArrayLength="1073741824" maxBytesPerRead="1073741824" maxNameTableCharCount="1073741824"/>
    </binding>
  </basicHttpBinding>
</bindings>

<behaviors>
  <endpointBehaviors>
    <behavior name="VInfotechEndPointBehavior">
      <dataContractSerializer maxItemsInObjectGraph="1500000000" />
    </behavior>
    <behavior name="UserSiteApp.MyServiceTypeBehaviors">
      <enableWebScript/>
    </behavior>
  </endpointBehaviors>

  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>



</behaviors>

<client>
  <!--Intranet Service-->
  <endpoint address="http://localhost:50004/Service1.svc" binding="basicHttpBinding" bindingConfiguration="Binding1" contract="your contracts Interface address" behaviorConfiguration="VInfotechEndPointBehavior" name="WSHttpBinding_IIntranet">
    <identity>
      <dns value="localhost"/>
    </identity>
  </endpoint>


    <identity>
      <dns value="localhost"/>
    </identity>
  </endpoint>

</client>

对于 WCF 服务 web 配置

    <system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
  <service name="VInfotech.Server.Intranet.IntranetService" behaviorConfiguration="IntranetService.Service1Behavior">
    <!-- Service Endpoints -->
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="Binding1" contract="VInfotech.Server.Intranet.IIntranet">
      <!-- 
          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>
  </service>
  <service name="VInfotech.Server.Intranet.MobileServicesController" behaviorConfiguration="ServBehave">
    <endpoint address="RestService" bindingConfiguration="StreamedRequestWebBinding" binding="webHttpBinding" behaviorConfiguration="restPoxBehavior" contract="VInfotech.Server.Intranet.IMobileServices" />
  </service>
</services>
<bindings>
  <webHttpBinding>
    <binding name="StreamedRequestWebBinding"
    bypassProxyOnLocal="true"
             useDefaultWebProxy="false"
             hostNameComparisonMode="WeakWildcard"
             sendTimeout="10:15:00"
             openTimeout="10:15:00"
             receiveTimeout="10:15:00"
             maxReceivedMessageSize="9223372036854775807"
             maxBufferPoolSize="9223372036854775807"
             maxBufferSize="2147483647"
             transferMode="StreamedRequest" >
      <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
    </binding>
  </webHttpBinding>
  <basicHttpBinding>
    <binding name="Binding1" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="1073741824" maxBufferPoolSize="1073741824" maxReceivedMessageSize="1073741824" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="1073741824" maxStringContentLength="1073741824" maxArrayLength="1073741824" maxBytesPerRead="1073741824" maxNameTableCharCount="1073741824"/>
    </binding>
    <!-- For Cyber Source bindings-->
    <binding name="ITransactionProcessor" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="1073741824" maxBufferPoolSize="1073741824" maxReceivedMessageSize="1073741824" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="1073741824" maxStringContentLength="1073741824" maxArrayLength="1073741824" maxBytesPerRead="1073741824" maxNameTableCharCount="1073741824"/>
      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
        <message clientCredentialType="UserName" algorithmSuite="Default"/>
      </security>
    </binding>
  </basicHttpBinding>
  <!--Cyber Source bindings ends here-->
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="IntranetService.Service1Behavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
    <behavior name="ServBehave">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <!--Behavior for the REST endpoint for Help enability-->
    <behavior name="restPoxBehavior">
      <webHttp helpEnabled="true" />
    </behavior>
    <behavior name="jsonBehavior">
      <enableWebScript />
    </behavior>
  </endpointBehaviors>
</behaviors>
<client>
  <endpoint address="https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor" binding="basicHttpBinding" bindingConfiguration="ITransactionProcessor" contract="ITransactionProcessor" name="portXML"/>
</client>
<diagnostics>
  <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxMessagesToLog="3000" maxSizeOfMessageToLog="2000"/>
</diagnostics>

希望这会帮助你。:)

于 2013-03-02T07:12:30.713 回答
0

将此更改<endpoint address="http://localhost:64049/Service/CrmService.svc/mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

并尝试http://localhost:64049/Service/CrmService.svc/mex引用您的服务。

更新:

你的合同应该是你的[ServiceContract]界面,除非CrmService是你的ServiceContract

<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="MapiWebService.ICrmService" behaviorConfiguration="webHttpBehavior" />
于 2013-03-01T20:08:13.073 回答