2013-03-01 62 views
0

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

回答

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" /> 
+0

谢谢你的回答。但是,它并没有解决这个问题。我收到了同样的错误。 – denious 2013-03-01 21:45:37

+0

另外,请记住,通常我甚至不需要指定服务的地址来引用它,因为我在同一个项目中。我只需在VS中打开添加服务参考对话框,然后单击发现>选择我的服务,然后就可以使用了。 – denious 2013-03-01 21:52:38

+0

之前未能注意到它,但'MapiWebService.CrmService'是你的'ServiceContract'? – Flowerking 2013-03-01 23:05:00

0

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

For Client App web config ..

 <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 SERVIC 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> 

希望这会帮助你。 :)

+0

客户和服务模式是什么意思?我想在自己的.NET应用程序项目中引用我的服务。在这种情况下谁是客户端,app.config应该放在哪里? – denious 2013-03-04 18:50:21

+0

所以你的意思是你的解决方案中只创建一个应用程序。通常在Web应用程序中,我们为我们的Web应用程序添加多个解决方案在同一场景中,我们正在Web应用程序中为服务创建一个单独的wcf项目。 – 2013-03-12 14:29:42

+0

Nilesh,你能向我解释为什么它有多少应用程序将使用我的服务?此外,我尝试从外部应用程序引用我的服务,并且我得到相同的异常。我真的没有任何线索... – denious 2013-03-15 13:34:11

相关问题