WCF返回“在实际环境中未找到终结点”

4

我可以帮助您进行翻译,这篇文章是关于it技术的,涉及到WCF服务在共享环境上的部署,其中包含两种不同的方法。其中一种方法可以返回所需的输出结果,而另一种方法则会导致“找不到终结点”的异常,这恰恰是我用来验证用户身份的主要方法。

下面是具体情况:

我的Iservice.cs代码如下:

[OperationContract]
[WebInvoke(Method="GET", UriTemplate = "Data?Id={id}", ResponseFormat=WebMessageFormat.Json)]
string GetData(string id);

[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "Login?InstId={inst}&UserId={user}&pwd={pwd}", ResponseFormat = WebMessageFormat.Json)]
string Authenticate(string inst, string user, string pwd);

然后通过 DAL 对用户详细信息进行身份验证,这部分工作正常。我的 Web Config 如下:

  <system.serviceModel>
    <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="True" aspNetCompatibilityEnabled="True">
    </serviceHostingEnvironment>-->
    <serviceHostingEnvironment multipleSiteBindingsEnabled="True">
    </serviceHostingEnvironment>
    <services>
      <service name="WCFDemo.Service1">
        <endpoint address="http://www.ekotri.com/Service1.svc" behaviorConfiguration="restfulBehavior"
                  binding="webHttpBinding" listenUri="/" bindingConfiguration="" contract="WCFDemo.IService1">
        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://www.ekotri.com" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="restfulBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="restfulBehavior">
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

GetData正常工作,但Authenticate出现了端点未找到的错误。虽然在本地IIS上运行良好。


尝试使用此文档启用帮助页面。同时,请检查实时和本地IIS的身份验证设置是否有任何差异。 - pepo
但是我有共享托管计划,那么如何在实际服务器上检查身份验证设置? - Shakil Sama
你尝试过将 UriTemplate = "Login?InstId={inst}&UserId={user}&pwd={pwd}" 更改为其他内容,例如 UriTemplate = "helloworld?InstId={inst}&UserId={user}&pwd={pwd}" 吗?也许有些东西正在阻止调用或在你不知情的情况下修改它。 - pepo
是的,我改了验证关键字之类的东西,但它没有发生变化……不知道我卡在哪里了??? - Shakil Sama
你尝试过将 address="" 留空吗?对我来说这样可以工作。 - ahaliav fox
3个回答

1

尝试使用此配置:

<system.serviceModel>
<!--<serviceHostingEnvironment multipleSiteBindingsEnabled="True" aspNetCompatibilityEnabled="True">
</serviceHostingEnvironment>-->
<serviceHostingEnvironment multipleSiteBindingsEnabled="True">
</serviceHostingEnvironment>
<services>
  <service name="WCFDemo.Service1">
    <endpoint address="rest" behaviorConfiguration="restfulBehavior"
              binding="webHttpBinding" contract="WCFDemo.IService1">
    </endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="http://www.ekotri.com/Service1.svc" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="restfulBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="restfulBehavior">
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>

我已经在Visual Studio的默认WCF应用程序项目上进行了测试,没有遇到任何问题。


不行啊兄弟,你的建议试了还是不行……我尝试后出现了这个错误:在服务 Service1 实现的契约列表中找不到“IMetadataExchange”合同名称。请向配置文件或 ServiceHost 直接添加 ServiceMetadataBehavior 以启用对此合同的支持。 - Shakil Sama
你确定 http://www.ekotri.com/Service1.svc 上的服务是你在问题中提到的实现 Iservice.cs 的服务吗?当我访问 http://www.ekotri.com/Service1.svc?wsdl 时,没有找到 Authenticate 方法。还是我漏掉了什么信息?不管我尝试哪个 URL,都会得到 endpoint not found 的提示。我认为我们正在调试错误的服务。 - pepo
请尝试以下链接: http://www.ekotri.com/Service1.svc/Data?Id=2 它是同一个服务类中的内容,但不是authenticate方法... - Shakil Sama
你从REST端点绑定中删除了listenUri属性吗?另外,你能否在restfulBehavior中启用webhttp的帮助页面,例如<webHttp helpEnabled="true" />?并且请粘贴你的服务类定义。 - pepo

1
尝试像这样更改您的界面:

[OperationContract]
 [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "Login/{inst}/{user}/{pwd}",
    BodyStyle = WebMessageBodyStyle.Bare)]
string Authenticate(string inst, string user, string pwd);

将此配置放置,
<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="customBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
        <message clientCredentialType="UserName" algorithmSuite="Default"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="asmx" name="WCFDemo.Service1">
    <endpoint address="basic" binding="basicHttpBinding" name="httpEndPoint" contract="WCFDemo.IService1"/>
    <endpoint address="json" binding="webHttpBinding" behaviorConfiguration="webBehavior" name="webEndPoint" contract="WebApplication1.IService"/>
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
  </service>
</services>
<behaviors>
    <endpointBehaviors>
        <behavior name="webBehavior">
            <webHttp />
        </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
    <behavior name="asmx">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>

1

您在尝试访问登录方法时使用的是哪个URL?

根据您的服务文件,您使用的URL模板为

Login?InstId={inst}&UserId={user}&pwd={pwd}

在您的配置文件中,您将其绑定到特定的域名/ URL 路径

<endpoint address="http://www.ekotri.com/Service1.svc" behaviorConfiguration="restfulBehavior"
                  binding="webHttpBinding" listenUri="/" bindingConfiguration="" contract="WCFDemo.IService1">

根据这两个信息,预期的访问路径将会是:
http://www.ekotri.com/Service1.svc/Login?InstId={inst}&UserId={user}&pwd={pwd}

如果我使用该模板URL并插入一些虚假值... 服务操作URL 此URL返回“False”,这是预期的。

是的,它返回了true和false,因为我在4天前解决了错误。因此,您得到了所需的输出。 - Shakil Sama
@shakil08it051 更新你的问题以表明你已经解决了它,或者自己回答来关闭这个问题。 - iamkrillin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接