我使用ASP.NET 4创建了一个WCF服务,并尝试在我自己的Web应用程序项目中连接到它,这给了我“找不到默认端点元素”错误。< / p>
这个类似问题的答案似乎都没有帮助我,因为他们似乎都在处理引用该服务并缺少配置文件的外部项目。 该服务在直接使用其方法时有效(例如: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 :(得分: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" />
答案 1 :(得分: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 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>
希望这会对你有所帮助。 :)