繁体   English   中英

ASP.NET Web应用程序的WCF服务中的InvalidOperationException

[英]InvalidOperationException in wcf service of asp.net web application

我刚刚创建了一个静态服务,并尝试通过实体框架访问数据。 我不在哪里纠正异常。请对此提供帮助
出现异常:System.ServiceModel.dll中发生了'System.InvalidOperationException'类型的异常,但未在用户代码中处理

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>

您应该在客户端的配置文件中定义要访问的端点。 像这样:

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

您不能通过添加服务引用或使用svcutil来使用生成的代理来调用rest服务。 使用http库或API(例如Web客户端,httpwebrequest)。

面对相同的问题后,我做了一些研究,结果发现我必须在服务部分中将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端点不同的路径,否则行为是不确定的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM