我刚刚创建了一个宁静的服务,并尝试通过实体框架访问数据。我不知道在哪里纠正异常。请帮助这个 例外情况: 类型' System.InvalidOperationException'的例外情况发生在System.ServiceModel.dll中但未在用户代码中处理
Additional information: Could not find default endpoint element that references contract 'ServiceReferenceCheck.ICheckDetails' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
my client code:
protected void Button1_Click(object sender, EventArgs e)
{
Entities.User u = new Entities.User();
u.UserName = TextBoxUN.Text;
u.Password = TextBoxP.Text;
ServiceReferenceCheck.CheckDetailsClient src=new ServiceReferenceCheck.CheckDetailsClient();//exception coming here
if(src.CheckLoginDetails(u))
{
Response.Redirect("Home.aspx?UN="+u.UserName);
}
else
{
LabelError.Text = "please check ur id and password once again";
}
}
my service web.config (part of it):
<system.serviceModel>
<services>
<service name="LoginServices.CheckDetails">
<endpoint address="" behaviorConfiguration="restfulBehaviour" binding="webHttpBinding" bindingConfiguration="" contract="LoginServices.ICheckDetails"></endpoint>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="restfulBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="webHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
答案 0 :(得分:0)
您应该在客户端的配置文件中定义您尝试访问的端点。像这样:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="WebHttpBinding">
</binding>
</webHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/Services/CheckDetails.svc"
binding="webHttpBinding" bindingConfiguration="WebHttpBinding"
contract="ICheckDetails"
name="ICheckDetailsEndpoint" />
</client>
</system.serviceModel>
答案 1 :(得分:0)
您无法使用生成的代理通过使用添加服务引用或使用svcutil来调用rest服务。使用http库或API,如web客户端,httpwebrequest。
答案 2 :(得分:0)
在面对同样的问题之后,我做了一些研究,结果发现我必须在服务部分中定义SOAP端点和REST端点。
生成的客户端代理类看起来只适用于SOAP服务端点。
最后,服务的web.config看起来像:
<system.serviceModel>
<services>
<service name="Service1" behaviorConfiguration="serviceBehavior">
<endpoint address="rest" binding="webHttpBinding" contract="Service1" behaviorConfiguration="restBehavior"/>
<endpoint address="" binding="wsHttpBinding" contract="Service1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="restBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="True" policyVersion="Policy15" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
请注意,REST端点必须具有与SOAP不同的路径,否则行为未定义。